在 Windows 7 上将 Boost.asio 与 MingW 结合使用时出现链接器错误
我尝试编译在 boost.asio 示例中找到的一个非常基本的示例,但出现链接器错误。这是我正在使用的完整命令行:
mingw32-c++.exe -L..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib -L..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib -o bin\Debug\CPP_WITHOUT_FEAR_1st_APP.exe obj\Debug\main.o obj\Debug\prog_2.o obj\Debug\timer.o obj\Debug\convert.o -lwsock32 ..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib\libboost_system-mgw45-mt-1_48.a
我遇到的错误:
..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib\libboost_system-mgw45-mt-1_48.a(error_code.o):error_code.cpp:(.text+0x148): undefined reference to `_Unwind_Resume' ..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib\libboost_system-mgw45-mt-1_48.a(error_code.o):error_code.cpp:(.text+0x16c4): undefined reference to `_Unwind_Resume' ..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib\libboost_system-mgw45-mt-1_48.a(error_code.o):error_code.cpp:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
试图找出问题所在,但我无法在任何地方找到答案。 谢谢, 斯里
I tried to compile a very basic example found on the boost.asio example but I'm getting linker error's. This is the complete command line I'm using:
mingw32-c++.exe -L..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib -L..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib -o bin\Debug\CPP_WITHOUT_FEAR_1st_APP.exe obj\Debug\main.o obj\Debug\prog_2.o obj\Debug\timer.o obj\Debug\convert.o -lwsock32 ..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib\libboost_system-mgw45-mt-1_48.a
The Errors I'm getting:
..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib\libboost_system-mgw45-mt-1_48.a(error_code.o):error_code.cpp:(.text+0x148): undefined reference to `_Unwind_Resume' ..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib\libboost_system-mgw45-mt-1_48.a(error_code.o):error_code.cpp:(.text+0x16c4): undefined reference to `_Unwind_Resume' ..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib\libboost_system-mgw45-mt-1_48.a(error_code.o):error_code.cpp:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
Tried to figure out what's wrong but I was unable to find the answer any where.
Thanks,
Sree
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试将 gcc 编译的目标文件与 g++ 编译的程序链接起来?
通常与当您打算指定 g++ 时将 gcc 指定为编译器有关
如果情况并非如此,您是否尝试使用 DW2 (Dwarf-2) 编译器链接使用 SJLJ (setjmp/longjmp) 编译的目标文件,反之亦然?
例如,您的程序的目标文件是由 mingw 编译的(版本 3.4.5 是 SJLJ),而 boost 是由 gcc 编译的(版本 4.4+ 是 DW2)?
如果是这种情况,请确保您的编译器和要链接的库是使用具有 SJLJ 异常处理或 DW2 异常处理的同一编译器编译的。
他们网站上的 minGW 4.40 beta 现在默认有 DW2,假设 boost 是用 DW2 编译的,那么应该可以干净地编译和链接。
至于SJLJ和DW2是什么,它们是异常处理的方法。 SJLJ 使用 setjmp 和 longjump,而 DW2 使用 DWARF-2(或 DWARF-3)调试信息。 SJLJ 较慢,但 DW2 需要更多空间,导致二进制文件较大。
有关异常处理的更多信息,请参阅此处
了解 DW2 的工作原理看这里
Are you trying to link object files compiled in gcc with your program compiled in g++ ?
is normally related to specifying gcc as the compiler when you meant to specify g++
If this isn't the case are you trying to link object files compiled with SJLJ (setjmp/longjmp) using a DW2 (Dwarf-2) compiler or vice versa ?
E.g. Were your program's object files compiled by mingw (version 3.4.5 is SJLJ) and boost compiled by gcc (version 4.4+ is DW2) ?
If this was the case, then ensure that your compiler and the libraries you are linking to were compiled with the same compiler, that has either SJLJ exception handling or DW2 exception handling.
The minGW 4.40 beta on their website has DW2 by default now, and assuming that boost was compiled with DW2, that should then compile and link cleanly.
As for what SJLJ and DW2 are they are methods of exception handling. SJLJ uses setjmp and longjump, whilst DW2 uses DWARF-2 (or DWARF-3) debugging information. SJLJ is slower but DW2 requires more space, leading to large binaries.
For more information about exception handling see here
For how DW2 works see here