Recently, I decided to try dabbling with C++, following my teacher's suggestion. I downloaded MinGW and started compiling some simple code with g++, but after some time any program I compiled wouldn't run, no matter how much I tried. I always got errors similar to this:
(My computer is in portuguese, I apologize. The message above translates to "The procedure [name of procedure] could not be located in the dynamic link library [name of compiled executable]". This particular error message shows up on a header generator tool I made, which was a single .cpp file. Other programs I compiled always show "Procedure entry point" errors when executing)
I'm compiling using the command g++ -o <filename>.exe -g -Wall *.cpp
(to debug and stuff), and I only have the mingw32-base-bin
and mingw32-gcc-g++-bin
packages installed. The only way I found for the compiled code to actually run is if I either compile the code with the command g++ <file> -static-libstdc++ -static-libgcc
(which results in bloated executable sizes even with simpler programs) or if I use a tool such as Visual Studio 2019. I also tried reinstalling MinGW, but it didn't work either.
Since I'm not doing anything larger than some class exercises, I'd really like to be able to compile my codes without having to use heavy-duty tools like Visual Studio, and I'd also like to know why it is necessary to add -static-libstdc++
and -static-libgcc
for it to work properly.
PS.: Another thing to note, is that compiling on my brand new laptop (that has the same MinGW configuration) worked fine. I talked with my teacher about this, and he thinks that the Microsoft C++ Redistributables (installed from things like tools and games) may be conflicting with the standard C++ library provided by MinGW. He wasn't really sure about that, though.
PS-2.: It seems extremely simple code works (things like Hello World). Anything more complex breaks apart. This is the simplest code I made where the error appeared: https://hastebin.com/aqamidoxom.cpp
Some standard library features are "header-only", so they are baked into your executable.
Others are more complex and live in the MinGW "runtime" DLL, which you must ship with your executable. Usually just putting it in the same directory as your executable, or putting it somewhere on your PC's %PATH
, is enough.
When you statically link the standard library, you sidestep that, because now everything from it is baked into your executable.
This has absolutely nothing to do with Visual Studio or its DLLs. (You will be using mcvcrt.dll
, in addition to the MinGW DLLs, but that is not to do with Visual Studio and it is always available on Windows.)
Further reading: