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's PATH environment variables

  • Confirming my MinGW installation by running g++ --version in cmd

  • 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's PATH environment variables

  • Confirming my MinGW installation by running g++ --version in cmd

  • 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.

Share Improve this question edited Mar 24 at 21:43 Remy Lebeau 601k36 gold badges507 silver badges851 bronze badges asked Mar 24 at 21:04 UhypocriteUhypocrite 275 bronze badges 5
  • 1 You have encountered DLL Hell or you've installed your tools such that the compiler can be found but the libraries the running program counts on cannot. – user4581301 Commented Mar 24 at 21:09
  • 1 Side note: currently using Msys2 to install your toolchain and libraries is the "correct"" way to get a GCC-based tool chain on Windows. You are probably better off asking about what went wrong with that install than asking about fixing whatever kit-bashed solution you're trying to use now. – user4581301 Commented Mar 24 at 21:14
  • 2 Side note: 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
  • stackoverflow/questions/66282133/… – Hans Passant Commented Mar 24 at 21:30
  • You always need to distribute the runtime library components matching the compiler you used, along with your program (except if you statically link everything). A .exe file is rarely a standalone thing. You can improve your question by showing us exactly how you compile and link your program. – Jesper Juhl Commented Mar 24 at 22:13
Add a comment  | 

2 Answers 2

Reset to default 4

The 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.

本文标签: