什么是造成这个运行时错误,我如何纠正它?

问题描述:

运行期间发生以下错误:

The following error occurred during runtime:


程序入口点 _ZSt24__throw_out_of_range_fmtPKcz 不能位于动态链接库test.exe中。

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 *,...)

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*, ...)

链接到以下库:


  • SDL2(动态,由来自自己编译,与我使用的GCC相同版本

  • 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从源代码编译SDL2与我在项目中使用的相同版本的GCC,因为我认为,我使用的预构建版本在某种程度上造成了不同的C ++标准库中的冲突。然后我尝试动态链接到这个构建,但是完全相同的运行时错误持续存在。

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.

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

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(SDL2的DLL implib)

  • libSDL2main.a

我只链接到动态链接库libSDL2.dll。我之前的怀疑是,因为SDL2是我自己编译之前预构建的,在编译器版本中存在冲突。然而,我现在知道情况并非如此。这个错误是由于我将GLEW源代码添加到我的项目而导致的。

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?

正确但是在正确的轨道:我打算使用的MinGW的版本不是很久以前安装到系统路径的MinGW的版本相同。这样做的结果是,可执行文件对G ++ DLL的依赖默认是针对我已经安装的MinGW版本的DLL;错误的版本。这会导致运行时错误。

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"

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

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

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.