是什么导致了这个运行时错误,我该如何纠正它?

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

运行时出现以下错误:

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

我使用 C++ demangler 找出导致入口点错误的函数。 函数为:std::__throw_out_of_range_fmt(char const*, ...)

我正在 link访问以下图书馆:

我使用与我在项目中使用的相同版本的 GCC 从源代码编译 SDL2,因为我认为我使用的 pre-built 版本在不同的 C++ 标准库中以某种方式引起了冲突。然后我尝试 link 动态地构建这个版本,但仍然存在完全相同的运行时错误。

编译和链接脚本日志(通过 Windows BATCH 脚本编译):

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

只有在运行时打印的错误信息才是这个问题的标题。我正在 link 访问以下库:

我只是 link 访问动态 link 库 libSDL2.dll。我之前的怀疑是因为SDL2在我自己编译之前是pre-built,所以编译器版本有冲突。然而,我现在知道事实并非如此。这个错误可能是由于我将 GLEW 源代码添加到我的项目中而导致的吗?

我最初的怀疑是不正确的,但在正确的轨道上:我打算使用的 MinGW 版本与我很久以前安装到系统路径中的 MinGW 版本不同。这样做的结果是,默认情况下,可执行文件对 G++ DLL 的依赖是针对我安装的 MinGW 版本的 DLL;错误的版本。这导致了运行时错误。

此问题已通过替换解决:

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

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

我将标志 -static-libgcc -static-libstdc++ 添加到命令中,这样我想使用的 MinGW 版本(在 "C:\MinGW\bin" 中)将静态 link 依赖关系到可执行文件中,以便不会发生冲突。我希望这可以帮助其他人解决类似棘手的问题。