15

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:\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
Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
Svalorzen
  • 5,353
  • 3
  • 30
  • 54
  • Please clarify your question. It may help to show the actual error output. – Jerry May 03 '12 at 05:54
  • Do you have the compiler output? What are the compiler and linker command lines? – jpalecek May 03 '12 at 11:15
  • 3
    Are you linking with `gcc` or `g++`? Note that your fix will cause null dereference and a nasty crash at runtime when an exception is thrown. – rubenvb May 03 '12 at 11:19
  • @jpalecek I've added the command line output, I hope it helps - some arguments ( hge, sfml ) are useless but that's because I've put them in my general configuration to avoid linking them in each project I do. – Svalorzen May 03 '12 at 12:28
  • 1
    See my answer to [this](http://stackoverflow.com/questions/7751640/undefined-reference-to-gxx-personality-sj0) related question. This sort of issue is usually due to a library/ABI mismatch between your compiler and the compiler that was used to compile the library. – Mankarse May 03 '12 at 12:36
  • @Mankarse I understand, and in fact I noticed that the library was compiled with g++, while I'm using mingw32-g++ to compile the code. However I can't figure out how to change the compiler that builds the library since it is using Scons and I'm not really familiar with it. – Svalorzen May 03 '12 at 18:51
  • Also I've just tried to compile/link my snippet with g++ ( which I used to build the library ) but the same error happens. – Svalorzen May 03 '12 at 19:25

3 Answers3

43

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.

Riot
  • 15,723
  • 4
  • 60
  • 67
  • 2
    Good answer. I ran into the `__Unwind_Resume` error when I was trying to revert to gcc 3 after using gcc 4. I had to go back and recompile two libraries with gcc 3 before I could link them. – tomlogic Mar 25 '15 at 18:21
1

I encountered that same problem attempting to use g++ -g -std=c++17 ... . I removed that option and, once I had removed use of a C++17 feature, it compiled, linked and ran.

0

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

Svalorzen
  • 5,353
  • 3
  • 30
  • 54