C++ Procedure Entry Point Not Found with MinGW
Asked Answered
G

1

6

I just started a C++ course and am using MinGW to compile (I started doing K&R so already had it set up for C). Whenever I compile a file that includes or uses any library it gives me the following error:

"The procedure entry point ... (this is just a long scrambles-looking thing) could not be located in the dynamic link library ...(the path for the file I'm compiling)"

After googling this I've tried placing libstdc++-6.dll in C:\Windows\System32, placing C:\MinGW\bin as first priority in PATH, and placing libstdc++-6.dll in the same folder as the .cpp file I am compiling.

The only solution was copying it to the folder of the .cpp file I am compiling, but I would like to avoid having to do that every time in the future.

Thanks in advance for the help!

Goodloe answered 29/1, 2018 at 16:22 Comment(6)
Add -static-libgcc -static-libstdc++ to your compiler flags.Pitman
thank you! could you explain what exactly that just did tho?Goodloe
These flags make GCC link the standard library (for C and C++ respectively) statically instead of dynamically. I.e. stuff from .dlls is now inside of the .exe (it probably grew in size by a few megabytes).Pitman
oh, alright! again, thank you! is there anything I can do to avoid having to statically link it every time?Goodloe
No, unless you want to copy the .dlls to the folder with your .exe. I assume you're compiling from a command line, so I'd suggest you to find a proper IDE. Then you won't care how lengthy your list of flags is.Pitman
Oh, alright! Thank you very much!Goodloe
D
5

When building with MinGW, the resulting binaries will need libstdc++-6.dll (and some others like libwinpthread-1.dll). They contain the standard C++ library, such as std::string and friends.

Upon execution your binary will look for these DLLs in specific locations. Usually the error is about a missing DLL, but in your case a wrong version of these DLLs appears to be installed somewhere on your computer without your knowledge. (e.g. 32bit vs 64 bit)

There are two possible solutions:

  • Find the correct DLLs that shipped with your MinGW toolchain and put them in the local directory. (The local directory is the first location where an executable searches for DLLs.) You will have to ship a copy of them along with your build.
  • Link the standard C++ library statically to your program by passing -static-libgcc -static-libstdc++ to the linker. This will increase the size of your binaries, and each binary will contain a redundant copy of the same routines. However, you'll get a self-contained binary.
Devonna answered 18/2, 2021 at 15:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.