C++ 对 _Unwind_Resume 和 __gxx_personality_v0 的未定义引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10419801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:02:17  来源:igfitidea点击:

Undefined reference to _Unwind_Resume and __gxx_personality_v0

c++exceptionmingw

提问by Svalorzen

I'm trying to use the JsonCpp library. I'm on Windows, using MinGW and CodeBlocks.

我正在尝试使用 JsonCpp 库。我在 Windows 上,使用 MinGW 和 CodeBlocks。

When I include anything from the json headers, my linker implodes and gives out this two errors. I've started to look around and I found these two other questions which basically describe my problem:

当我从 json 头文件中包含任何内容时,我的链接器会内爆并给出这两个错误。我开始环顾四周,发现另外两个问题基本上描述了我的问题:

problem with g++ and "undefined reference to `__gxx_personality_v0'"

g++ 的问题和“对‘__gxx_personality_v0’的未定义引用”

What is __gxx_personality_v0 for?

__gxx_personality_v0 有什么用?

And if I declare the two missing variables as void pointers, like below, the problem goes away:

如果我将两个缺失的变量声明为空指针,如下所示,问题就会消失:

void * __gxx_personality_v0=0;
void * _Unwind_Resume =0;

However, I don't understand why this error happens. CodeBlocks is set up so that it uses migw32-g++ for cpp files, and also adding the -lstdc++ option does not fix the problem. Neither does the option -fno-exception ( I want exceptions, mind you, I was just trying ).

但是,我不明白为什么会发生此错误。CodeBlocks 设置为对 cpp 文件使用 migw32-g++,并且添加 -lstdc++ 选项也不能解决问题。选项 -fno-exception 也没有(我想要例外,请注意,我只是在尝试)。

I'm also including a boost library in the same file and that does not cause any problems.

我还在同一个文件中包含了一个 boost 库,这不会导致任何问题。

EDIT:

编辑:

The error output is exactly what I said in my title: I get a total of 22 undefined references to _Unwind_Resume and __gxx_personality_v0 during the linking. My code is:

错误输出正是我在标题中所说的:在链接期间,我总共得到了 22 个对 _Unwind_Resume 和 __gxx_personality_v0 的未定义引用。我的代码是:

#include <boost/algorithm/string.hpp>
#include <include/json/value.h>
//void * __gxx_personality_v0=0;
//void * _Unwind_Resume =0;
int main () {
    std::string str1("Hello world!");
    boost::to_upper(str1);
    Json::Value k;
    return 0;
}

The error is there only when I include/use the JsonCPP library. Uncommenting the commented lines fixes the problem.

只有当我包含/使用 JsonCPP 库时才会出现错误。取消注释注释行可以解决问题。

The command line output is this:

命令行输出是这样的:

mingw32-g++.exe -Wall -fexceptions  -g  -DSFML_DYNAMIC   -IC:\Users\Svalorzen\Documents\Projects\boost_1_49 -IC:\Users\Svalorzen\Documents\Projects\jsoncpp-src-0.5.0 -IC:\Users\Svalorzen\Documents\Projects\SFML-1.6\include -IC:\Users\Svalorzen\Documents\Projects\hge181\include  -c C:\Users\Svalorzen\Documents\Projects\test\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LC:\Users\Svalorzen\Documents\Projects\jsoncpp-src-0.5.0 -LC:\Users\Svalorzen\Documents\Projects\SFML-1.6\lib -LC:\Users\Svalorzen\Documents\Projects\hge181\lib  -o bin\Debug\test.exe obj\Debug\main.o   -fno-exceptions -lsfml-graphics -lsfml-window -lsfml-system  C:\Users\Svalorzen\Documents\Projects\jsoncpp-src-0.5.0\libs\mingw\libjson_mingw_libmt.a C:\Users\Svalorzen\Documents\Projects\hge181\lib\gcc\libhge.a C:\Users\Svalorzen\Documents\Projects\hge181\lib\gcc\libhelp.a 
Output size is 1.22 MB
Process terminated with status 0 (0 minutes, 3 seconds)
0 errors, 0 warnings

SECOND EDIT: I'm adding the command lines I use to compile the library:

第二次编辑:我正在添加用于编译库的命令行:

g++ -o buildscons\mingw\src\lib_json\json_reader.o -c -DWIN32 -DNDEBUG -D_MT -Iinclude src\lib_json\json_reader.cpp
g++ -o buildscons\mingw\src\lib_json\json_value.o -c -DWIN32 -DNDEBUG -D_MT -Iinclude src\lib_json\json_value.cpp
g++ -o buildscons\mingw\src\lib_json\json_writer.o -c -DWIN32 -DNDEBUG -D_MT -Iinclude src\lib_json\json_writer.cpp
ar rc buildscons\mingw\src\lib_json\libjson_mingw_libmt.a buildscons\mingw\src\lib_json\json_reader.o buildscons\mingw\src\lib_json\json_value.o buildscons\mingw\src\lib_json\json_writer.o
ranlib buildscons\mingw\src\lib_json\libjson_mingw_libmt.a

采纳答案by Svalorzen

I finally fixed this by importing into Code::Blocks the source code of JsonCpp and creating the library myself. I am still baffled though as to why the library created with Scons didn't work, since it was using the same compiler that Code::Blocks uses, but at the same time it was not ( or the error wouldn't have been there ).

我最终通过将 JsonCpp 的源代码导入 Code::Blocks 并自己创建库来解决此问题。我仍然很困惑,为什么用 Scons 创建的库不起作用,因为它使用的是 Code::Blocks 使用的相同编译器,但同时它不是(或者错误不会出现在那里)。

回答by Riot

For those coming to this from google (like i did), the real cause of the undefined references to _Unwind_Resumeand __gxx_personality_v0is "using a gcc that uses a different stack unwinding method than dwarf2" [1]

对于那些来这从谷歌(如我一样),对未定义的引用的真正原因_Unwind_Resume__gxx_personality_v0被“利用使用不同的堆栈展开方法比DWARF2一个gcc” [ 1]

In my case it was attempting to link code compiled with GCC 4.9 upwards with a library compiled with GCC 4.8 or below. The solution is to recompile the library with the same compiler you're building with.

就我而言,它试图将使用 GCC 4.9 编译的代码与使用 GCC 4.8 或更低版本编译的库向上链接。解决方案是使用您正在构建的相同编译器重新编译库。