使用jsoncpp出现,json_test.cpp:(.text+0x2c): undefined reference to `Json::Value::Value(Json::ValueType)问 2022-06-13 17:24:46

使用jsoncpp出现,json_test.cpp:(.text+0x2c): undefined reference to `Json::Value::Value(Json::ValueType)问题

nvidia@nvidia-desktop:~/Desktop/work/c_project$ g++ json_test.cpp -o json_test
/tmp/ccrEc2Of.o: In function parseJson()': json_test.cpp:(.text+0x2c): undefined reference to Json::Value::Value(Json::ValueType)’
json_test.cpp:(.text+0x38): undefined reference to Json::Value::Value(Json::ValueType)' json_test.cpp:(.text+0x44): undefined reference to Json::Value::Value(Json::ValueType)’
json_test.cpp:(.text+0x68): undefined reference to Json::CharReaderBuilder::CharReaderBuilder()' json_test.cpp:(.text+0x90): undefined reference to Json::CharReaderBuilder::operator[](std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)’
json_test.cpp:(.text+0xa0): undefined reference to Json::Value::Value(bool)' json_test.cpp:(.text+0xb0): undefined reference to Json::Value::operator=(Json::Value&&)’
json_test.cpp:(.text+0xb8): undefined reference to Json::Value::~Value()' json_test.cpp:(.text+0xe4): undefined reference to Json::parseFromStream(Json::CharReader::Factory const&, std::istream&, Json::Value*, std::__cxx11::basic_string<char, std::char_traits, std::allocator > )’
json_test.cpp:(.text+0x150): undefined reference to Json::Value::operator[](char const*)' json_test.cpp:(.text+0x164): undefined reference to Json::Value::asString abi:cxx11 const’
json_test.cpp:(.text+0x1bc): undefined reference to Json::Value::operator[](char const*)' json_test.cpp:(.text+0x1c0): undefined reference to Json::Value::asInt() const’
json_test.cpp:(.text+0x1f4): undefined reference to Json::Value::operator[](char const*)' json_test.cpp:(.text+0x200): undefined reference to Json::Value::operator=(Json::Value const&)’
json_test.cpp:(.text+0x220): undefined reference to Json::Value::size() const' json_test.cpp:(.text+0x248): undefined reference to Json::Value::operator
json_test.cpp:(.text+0x258): undefined reference to Json::operator<<(std::ostream&, Json::Value const&)' json_test.cpp:(.text+0x2a4): undefined reference to Json::Value::operator[](char const
)’
json_test.cpp:(.text+0x2b0): undefined reference to Json::Value::operator=(Json::Value const&)' json_test.cpp:(.text+0x2d8): undefined reference to Json::Value::operator[](char const*)’
json_test.cpp:(.text+0x2ec): undefined reference to Json::Value::asString[abi:cxx11]() const' json_test.cpp:(.text+0x344): undefined reference to Json::Value::operator[](char const*)’
json_test.cpp:(.text+0x358): undefined reference to Json::Value::asString[abi:cxx11]() const' json_test.cpp:(.text+0x39c): undefined reference to Json::CharReaderBuilder::~CharReaderBuilder()’
json_test.cpp:(.text+0x3ac): undefined reference to Json::Value::~Value()' json_test.cpp:(.text+0x3b4): undefined reference to Json::Value::~Value()’
json_test.cpp:(.text+0x3bc): undefined reference to Json::Value::~Value()' json_test.cpp:(.text+0x444): undefined reference to Json::CharReaderBuilder::~CharReaderBuilder()’
json_test.cpp:(.text+0x464): undefined reference to Json::Value::~Value()' json_test.cpp:(.text+0x474): undefined reference to Json::Value::~Value()’
json_test.cpp:(.text+0x484): undefined reference to `Json::Value::~Value()

libjsoncpp.a库没有正确链接。

g++ json_test.cpp -o json_test -L/usr/local/lib /usr/local/lib/libjsoncpp.a
                                    最近在Qt的项目中使用JSON库的时候,出现了挺多错误的,一个是链接库的错误,环境是UNBUNTU16.4,本以为系统中已经安装了jsoncpp的库了,结果却无法链接。
正确做法是,添加链接即可:
LIBS +=  -L/usr/local/lib   /usr/local/lib/libjsoncpp.a
这里使用json库时jsoncpp库,下载地址:jsoncpp-master.zip:
                                    增加了依赖库的路径,同时要指定连接的库.。 依赖的库是libjsoncpp.so ,路径是工程目录的lib目录下。 需要在Makefile文件中增加的命令是:
LDFLAGS= -L./lib
LDFLAGS =-ljsoncpp
                                    1, test.cpp:(.text+0xc): undefined reference to `std::cout'
test.cpp:(.text+0x22): undefined reference to `std::ostream::operator<<(int)'
test.cpp:(.text+0x2a): undefined reference to `std::basic_ostr
                                    一般出现cxx11 const' 应该都是gcc的版本不一样。 我遇到的情况是jsoncpp生成的动态库和依赖它而生成的动态库的gcc版本不同。
使用 gcc -v 指令来查看 gcc的版本
GCC5.1发布时,为libstdc++添加了新的特性,旧版就无法兼容了。为了避免混乱,对于旧版而言,有旧版(c++03规范)的libstdc++.so。也就是说有两个库,旧版(c++03规范)的libstdc++.so和新版(c++11规范)的libstdc++.so同时存在。
为了避免两个库到底选择哪...
sudo apt-get install libjsoncpp-dev
系统会自动安装,静态库在系统:/usr/include;动态库在:/usr/lib/x84_64-linux-gnu ;
在动态库里面会有libjsoncpp.a文件。
出现这个题就是CMake 没有引用...
[root@node1 windows_share]# g++ jsoncpp_test.cc 
/tmp/ccAclhTh.o: In function `main':
jsoncpp_test.cc:(.text+0x51): undefined reference to `Json::Reader::Reader()'
jsoncpp_test.cc:(.t
在CentOS系统上安装了gcc4.8.2和gcc7.2两个版本,gcc使用的是4.8.2版本,g++使用的是7.2版本,使用make编译cmake时出现c++11标准库未定义错误,两个版本的编译器使用的库版本也不同,对c++11标准的实现程度也不一样,所以会出现题,将g++换成4.8.2版本即解决该题。
个人感觉编译器报标准库的错误很可能就是工具链版本的题,修改使用合适的工具链应该即可,比如对gcc软件,所有编译器都使用统一版本即可。
————————————————
一,二进制文件的类型
 Linux下的二进制文件是ELF格式的,主要有目标文件、静态链接库文件、动态链接库文件、可执行文件和core dump文件。可以使用如下命令查看其类型:
 file 文件名。
 我们还是以之前的例子test.c举例,test.c的源代...
undefined reference to `Json::Value::Value
根据这个链接的说法,you have jsoncpp compiled with a different C++ ABI than you link against. The easiest solution is to use exactly the same compiler-version to build both library and executable. jsoncpp使用了其他的c+