简体   繁体   English

VS 代码 C++:“退出代码 = 3221225785”

[英]VS code c++: "exited with code=3221225785"

I'm a complete novice to VS code, and I've only been coding with C++ for around a month.我是 VS 代码的完全新手,我只使用 C++ 编码大约一个月。 I tried this bare bones program to make sure things were set up correctly:我尝试了这个简单的程序来确保一切设置正确:

#include <iostream>
#include <vector>
using namespace std;

int main() {

cout << "Hello world" << endl;
vector<int> v;
return 0;

}

Nothing shows up when running the executable.运行可执行文件时没有任何显示。 Removing the vector declaration causes the program to run normally.删除向量声明会使程序正常运行。

I did find this which encountered a similar problem with declaring a string, and the solution (static linking with -static-libstdc++) works for me, though the author who gave the solution wasn't entirely sure why it worked either.我确实发现这个在声明字符串时遇到了类似的问题,并且解决方案(与 -static-libstdc++ 的静态链接)适用于我,尽管提供解决方案的作者也不完全确定它为什么有效。

However , since I'm a noob, I don't understand that well why static linking fixed my problem, even after reading this , and am worried about some of the drawbacks mentioned (it recommends only linking statically if you absolutely have to since disadvantages outweight advantages) , so I was wondering if there was some other solution besides static linking.但是,因为我是菜鸟,我不太明白为什么静态链接解决了我的问题,即使在阅读了这篇文章之后,我也担心提到的一些缺点(它建议只在绝对必要的情况下静态链接,因为缺点outweight advantages) ,所以我想知道除了静态链接之外是否还有其他解决方案。

EDIT: Clarification--the program's outputs now show up normally in terminal, but in the output window, the same exit code still appears.编辑:澄清——程序的输出现在在终端中正常显示,但在输出窗口中,仍然出现相同的退出代码。

Configure VSCode as given below for "VS Code C++: exited with code=3221225785"如下所示为“VS Code C++: exited with code=3221225785”配置 VSCode

Install the Code Runner Extension of Visual Studio Code.安装 Visual Studio Code 的 Code Runner 扩展。

Open the Settings(Seetings.json).打开设置(Seetings.json)。

Search "code-runner.executorMap" in the Search bar.在搜索栏中搜索“code-runner.executorMap”。

modify调整

"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt  && $dir$fileNameWithoutExt",

to

"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt -static && $dir$fileNameWithoutExt",

After that Right Click on source code file select the option Run Code.之后右键单击源代码文件,选择运行代码选项。

For DEBUG:对于调试:

add an extra parameter "-static" in "args" of tasks.json file.在 tasks.json 文件的“args”中添加一个额外的参数“-static”。

Before:前:

"args": [

                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"  

            ],

After:后:

"args": [

                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-static"

            ],

"- static" is static linking parameter when we compiling and running. “-static”是我们编译运行时的静态链接参数。

For me solved when I put the file libstdc++-6.dll on folder that I needed debug.当我将文件 libstdc++-6.dll 放在我需要调试的文件夹中时,我就解决了。

This file is in "\MinGW\bin".该文件位于“\MinGW\bin”中。

I also encountered the same situation, due to the environment variable access error, because I installed MATLAB on my computer first,the environment variable D: matlab\bin also contains the libstdc++-6.dll link library, so the computer will first access D:\ matlab\bin instead of C: \mingw64\bin.我也遇到同样的情况,由于环境变量访问错误,因为我先在电脑上安装了MATLAB,环境变量D:matlab\bin中也包含了libstdc++-6.dll链接库,所以电脑会先访问D :\ matlab\bin 而不是 C:\mingw64\bin。 So what we need to do is to move the C:\ mingw64\bin environment variable in front of the D:\ matlab\bin environment variable in the computer properties environment variable to solve this problem。那么我们需要做的就是将计算机属性环境变量中的C:\mingw64\bin环境变量移到D:\matlab\bin环境变量前面来解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM