Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

c++ - Undefined reference to _Unwind_Resume and __gxx_personality_v0

I'm trying to use the JsonCpp library. I'm on Windows, using MinGW and 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:

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

What is __gxx_personality_v0 for?

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

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

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:

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

The command line output is this:

mingw32-g++.exe -Wall -fexceptions  -g  -DSFML_DYNAMIC   -IC:UsersSvalorzenDocumentsProjectsoost_1_49 -IC:UsersSvalorzenDocumentsProjectsjsoncpp-src-0.5.0 -IC:UsersSvalorzenDocumentsProjectsSFML-1.6include -IC:UsersSvalorzenDocumentsProjectshge181include  -c C:UsersSvalorzenDocumentsProjectsestmain.cpp -o objDebugmain.o
mingw32-g++.exe -LC:UsersSvalorzenDocumentsProjectsjsoncpp-src-0.5.0 -LC:UsersSvalorzenDocumentsProjectsSFML-1.6lib -LC:UsersSvalorzenDocumentsProjectshge181lib  -o binDebugest.exe objDebugmain.o   -fno-exceptions -lsfml-graphics -lsfml-window -lsfml-system  C:UsersSvalorzenDocumentsProjectsjsoncpp-src-0.5.0libsmingwlibjson_mingw_libmt.a C:UsersSvalorzenDocumentsProjectshge181libgcclibhge.a C:UsersSvalorzenDocumentsProjectshge181libgcclibhelp.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 buildsconsmingwsrclib_jsonjson_reader.o -c -DWIN32 -DNDEBUG -D_MT -Iinclude srclib_jsonjson_reader.cpp
g++ -o buildsconsmingwsrclib_jsonjson_value.o -c -DWIN32 -DNDEBUG -D_MT -Iinclude srclib_jsonjson_value.cpp
g++ -o buildsconsmingwsrclib_jsonjson_writer.o -c -DWIN32 -DNDEBUG -D_MT -Iinclude srclib_jsonjson_writer.cpp
ar rc buildsconsmingwsrclib_jsonlibjson_mingw_libmt.a buildsconsmingwsrclib_jsonjson_reader.o buildsconsmingwsrclib_jsonjson_value.o buildsconsmingwsrclib_jsonjson_writer.o
ranlib buildsconsmingwsrclib_jsonlibjson_mingw_libmt.a
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For those coming to this from google (like i did), the real cause of the undefined references to _Unwind_Resume and __gxx_personality_v0 is "using a gcc that uses a different stack unwinding method than dwarf2" [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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...