admin管理员组文章数量:1395730
I’m facing an issue where declaring variables from the C++ standard library headers - like <string>
, <vector>
, <stack>
, or <queue>
- causes my program to fail when launched. Functions from <iostream>
and <math.h>
work as expected.
I am running Windows 10, using MinGW as my compiler, using VS Code as my IDE, and using the C++ VS Code extension.
My program runs fine when I use basic output (e.g., cout
) or math functions (e.g., sqrt
), but declaring variables like string
, vector
, stack
, or queue
, causes it to compile successfully but fail to execute.
I'm testing this with MinGW (downloaded from SourceFe) in both VS Code and the command line.
Here's an example that fails. Note that this code runs if I comment out the string:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string testString;
cout << "Hello, World!" << endl;
}
VS Code's debug console gives the following error when it runs:
ERROR: During startup program exited with code 0xc0000139
Running the .exe
from the command line gives this error:
Entry Point Not Found
The procedure entry point ZNSt7__cxx1112basic_stringlcSt11char_traitslcESalcEEC1EPKcRKS3 could not be located in the dynamic link library
Here's what I have tried:
confirming that MinGW's
bin
folder is in my system'sPATH
environment variablesConfirming my MinGW installation by running
g++ --version
incmd
Reinstalling MinGW with all packages
Reinstalling both VS Code and the C++ extension
Installing the latest Visual C++ Redistributable
Compiling from the command line and with VS Code
Restarting my computer
Installing msys2 instead, but that was giving me errors for different reasons. I have removed my msys2 installation.
I’m facing an issue where declaring variables from the C++ standard library headers - like <string>
, <vector>
, <stack>
, or <queue>
- causes my program to fail when launched. Functions from <iostream>
and <math.h>
work as expected.
I am running Windows 10, using MinGW as my compiler, using VS Code as my IDE, and using the C++ VS Code extension.
My program runs fine when I use basic output (e.g., cout
) or math functions (e.g., sqrt
), but declaring variables like string
, vector
, stack
, or queue
, causes it to compile successfully but fail to execute.
I'm testing this with MinGW (downloaded from SourceFe) in both VS Code and the command line.
Here's an example that fails. Note that this code runs if I comment out the string:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string testString;
cout << "Hello, World!" << endl;
}
VS Code's debug console gives the following error when it runs:
ERROR: During startup program exited with code 0xc0000139
Running the .exe
from the command line gives this error:
Entry Point Not Found
The procedure entry point ZNSt7__cxx1112basic_stringlcSt11char_traitslcESalcEEC1EPKcRKS3 could not be located in the dynamic link library
Here's what I have tried:
confirming that MinGW's
bin
folder is in my system'sPATH
environment variablesConfirming my MinGW installation by running
g++ --version
incmd
Reinstalling MinGW with all packages
Reinstalling both VS Code and the C++ extension
Installing the latest Visual C++ Redistributable
Compiling from the command line and with VS Code
Restarting my computer
Installing msys2 instead, but that was giving me errors for different reasons. I have removed my msys2 installation.
2 Answers
Reset to default 4The issue boils down to the fact that your C++ program is more than just the .exe file itself. It also relies on a C++ runtime that in your case appears to be provided dll files (which were presumably provided with MinGW). Your error message, while complex and scary looking, is basically saying it cannot find the constructor to std::string.
There are a few ways you can diagnose the problem. This post describes some of the required DLLs for MinGW programs. If you have dumpbin installed you can use it to examine the dependencies.
How to check for DLL dependency?
You want to make sure that those DLLs are either in your search path or in the same directory as the .exe file itself. I generally put them with the .exe. Microsoft documents the DLL search order here.
Alternatively you can attempt to statically link the C++ runtime into your program and make your .exe file standalone.
Thank you very much for the replies, I certainly was in DLL Hell. As suggested, I switched my compiler to msys2 but I was still getting a very similar DLL error when trying to compile my code from cmd
:
The procedure entry point crc32_combine could not be located in the dynamic link library C:\msys64\ucrt54\bin\..\lib\gcc\x86_64-w64-mingw32\14.2.0\cc1plus.exe
I ended up spending a while going back and forth with chat gpt to troubleshoot the error and was eventually recommended to try a where zlib1.dll
command in cmd
. This pointed me to a folder called GtkSharp
which after deleting, resolved any issues I had compiling or running my code from cmd
. Unfortunately I am not positive where this folder came from in the first place, my best guess would be that it was something left over from a previous compiler installation.
At this point Vs code was now giving me an error:
(preLaunchTask 'C/C++: g++.exe build active file' terminated with exit code -1)
but Deleting the .vscode folder of my project let the code compile.
I can’t say for certain that what I did would resolve my original error as I’m quite happy leaving well enough alone at this point. I am also uncertain where chat gpt got zlib1.dll
from.
本文标签:
版权声明:本文标题:Why does declaring variables from C++ standard library headers (e.g., string, vector) cause my program to fail with MinGW? - Sta 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744228682a2596219.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
g++ --version
lets you know you have a compiler installed. It's the building and running of Hello World program you're currently struggling with that tells you whether or not you have the tools installed correctly. – user4581301 Commented Mar 24 at 21:16