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,使它使用migw32-g++作为cpp文件,并且添加-lstdc++选项并不能解决问题。选项也不例外(我想要例外,请注意,我只是在尝试)。
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
2 个解决方案
#1
24
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]
对于从谷歌(像我这样做)来的人来说,对_Unwind_Resume和__gxx_personality_v0的未定义引用的真正原因是“使用一个使用不同堆栈展开方法的gcc[1]”[0]
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或以下的库进行编译。解决方案是使用正在构建的同一个编译器重新编译库。
#2
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 ).
我最终通过导入代码来修复这个问题::阻塞JsonCpp的源代码并自己创建库。我仍然困惑于为什么使用Scons创建的库没有工作,因为它使用的是代码::block使用的相同的编译器,但同时它不是(或者错误不会出现在那里)。
#1
24
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]
对于从谷歌(像我这样做)来的人来说,对_Unwind_Resume和__gxx_personality_v0的未定义引用的真正原因是“使用一个使用不同堆栈展开方法的gcc[1]”[0]
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或以下的库进行编译。解决方案是使用正在构建的同一个编译器重新编译库。
#2
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 ).
我最终通过导入代码来修复这个问题::阻塞JsonCpp的源代码并自己创建库。我仍然困惑于为什么使用Scons创建的库没有工作,因为它使用的是代码::block使用的相同的编译器,但同时它不是(或者错误不会出现在那里)。