Harrand Harrand - 3 months ago 28
C++ Question

What's causing this runtime error and how can I rectify it?

The following error occurred during runtime:


The procedure entry point
_ZSt24__throw_out_of_range_fmtPKcz
could not be located in the dynamic link library "test.exe".


I used a C++ demangler to find out which function is causing the entry point error.
The function is:
std::__throw_out_of_range_fmt(char const*, ...)


I am linking to the following libraries:


  • SDL2 (Dynamic, compiled from source by myself, same version of GCC that I'm using for my project (4.9.3)).

  • GLEW (Added source to project)



I compiled SDL2 from source with the same version of GCC that I use in my project because I thought that the pre-built version I was using had somehow caused a conflict in the different C++ Standard Libraries. I then attempted to link dynamically to this build, but the exact same runtime error persisted.

Compilation & Linking Script Log (Compiled via a Windows BATCH script):

C:\Users\Harrand\Desktop\Ocular GEng\src\camera.o
C:\Users\Harrand\Desktop\Ocular GEng\src\datatranslation.o
C:\Users\Harrand\Desktop\Ocular GEng\src\glew.o
C:\Users\Harrand\Desktop\Ocular GEng\src\light.o
C:\Users\Harrand\Desktop\Ocular GEng\src\listeners.o
C:\Users\Harrand\Desktop\Ocular GEng\src\matrix.o
C:\Users\Harrand\Desktop\Ocular GEng\src\mesh.o
C:\Users\Harrand\Desktop\Ocular GEng\src\model_loader.o
C:\Users\Harrand\Desktop\Ocular GEng\src\object.o
C:\Users\Harrand\Desktop\Ocular GEng\src\quaternion.o
C:\Users\Harrand\Desktop\Ocular GEng\src\shader.o
C:\Users\Harrand\Desktop\Ocular GEng\src\stb_image.o
C:\Users\Harrand\Desktop\Ocular GEng\src\test.o
C:\Users\Harrand\Desktop\Ocular GEng\src\texture.o
C:\Users\Harrand\Desktop\Ocular GEng\src\timekeeper.o
C:\Users\Harrand\Desktop\Ocular GEng\src\utility.o
C:\Users\Harrand\Desktop\Ocular GEng\src\vector.o
C:\Users\Harrand\Desktop\Ocular GEng\src\window.o
C:\Users\Harrand\Desktop\Ocular GEng\src\world.o
19 file(s) moved.
Compilation Completed, ".o" files are in "C:\Users\Harrand\Desktop\Ocular GEng\cpl\Thu 08.25.2016"
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.9.3/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-4.9.3/configure --build=x86_64-pc-linux-gnu --host=mingw32 --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --enable-libstdcxx-debug --with-tune=generic --enable-nls
Thread model: win32
gcc version 4.9.3 (GCC)
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.9.3/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.9.3/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../
COLLECT_GCC_OPTIONS='-v' '-LC:\Users\Harrand\Desktop\Ocular GEng\lib' '-LC:\Users\Harrand\Desktop\Ocular GEng\Lua\5.3.2\lib' '-o' 'oculargame-test.exe' '-shared-libgcc' '-mtune=generic' '-march=i586'
c:/mingw/bin/../libexec/gcc/mingw32/4.9.3/collect2.exe -plugin c:/mingw/bin/../libexec/gcc/mingw32/4.9.3/liblto_plugin-0.dll -plugin-opt=c:/mingw/bin/../libexec/gcc/mingw32/4.9.3/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\Harrand\AppData\Local\Temp\ccUhcnbk.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -Bdynamic -u ___register_frame_info -u ___deregister_frame_info -o oculargame-test.exe c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../crt2.o c:/mingw/bin/../lib/gcc/mingw32/4.9.3/crtbegin.o -LC:\Users\Harrand\Desktop\Ocular GEng\lib -LC:\Users\Harrand\Desktop\Ocular GEng\Lua\5.3.2\lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.9.3 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../.. camera.o datatranslation.o glew.o light.o listeners.o matrix.o mesh.o model_loader.o object.o quaternion.o shader.o stb_image.o test.o texture.o timekeeper.o utility.o vector.o window.o world.o -lOpenGL32 -lSDL2 -lSDL2main C:\Users\Harrand\Desktop\Ocular GEng\res\exe\ocular.res -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc/mingw32/4.9.3/crtend.o
1 file(s) moved.
Linking Completed, "oculargame-test.exe" is in "C:\Users\Harrand\Desktop\Ocular GEng\cpl\Thu 08.25.2016\lnk"


Only error message printed during runtime is the title of this question. I am linking to the following libs:


  • libSDL2.a (DLL implib for SDL2)

  • libSDL2main.a



I am only linking to the dynamic link library libSDL2.dll. My previous suspicion was that because SDL2 was pre-built before I compiled it myself, there was a conflict in the compiler versions. However, I now know that this isn't the case. Could this error be somehow caused by the fact that I added the GLEW source code to my project?

Answer

My initial suspicion was not correct but on the right tracks: The version of MinGW which I intended to use was NOT the same as the version of MinGW that I installed into the system path long ago. The effect of this was that the dependency that an executable has on the G++ DLLs was, by default, targeting the DLLs of the version of MinGW which I had installed; the wrong version. This caused the runtime error.

This problem was resolved by replacing:

"C:\MinGW\bin\g++"*.o -L%libdir% -L"%scriptdir%\Lua\5.3.2\lib" -lOpenGL32 -lSDL2 -lSDL2main "%scriptdir%\res\exe\ocular.res" -o "oculargame-test.exe"

with

"C:\MinGW\bin\g++" -static-libgcc -static-libstdc++ *.o -L%libdir% -L"%scriptdir%\Lua\5.3.2\lib" -lOpenGL32 -lSDL2 -lSDL2main "%scriptdir%\res\exe\ocular.res" -o "oculargame-test.exe"

I added the flags -static-libgcc -static-libstdc++ to the command so that the MinGW version that I wanted to use (In "C:\MinGW\bin") would statically link the dependencies into the executable so that the conflict would not occur. I hope this helps others with similarly tricky issues.