我是C++和cLion的新手,我使用JsonCpp将对象解析为文本,反之亦然。我是一个mac用户,我的.h jsoncpp文件存储在/usr/include/jsoncpp中,.dylib存储在/usr/lib中。
在我的项目中包含jsoncpp库的方法是什么?我试过:
include_directories(/usr/include/jsoncpp)我可以#include <json.h>,但是还有另一个错误,如下所示:
Undefined symbols for architecture x86_64:
"Json::Value::Value(Json::ValueType)", referenced from:
Account::toJson() in Account.cpp.o
StorageLoad::readfile(std::__1::basic_ifstream<char, std::__1::char_traits<char> >&) in StorageLoad.cpp.o
"Json::Value::Value(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
Account::toJson() in Account.cpp.o如何解决此错误?我花了好几个小时去尝试,但没有结果。
发布于 2021-10-12 01:50:23
此解决方案工作在CLion 2021.1.3 (Mac 11.6)上。
所提供的解决方案基于这个线程,它讨论了一个类似的问题,但是使用了一个不同的库。
使用终端和命令使用自制软件安装库:
brew install jsoncpp
然后,您需要安装位置。通过安装的输出或使用命令:
brew info jsoncpp
应该列出路径,如下所示:
/usr/local/Cellar/jsoncpp/1.9.4_1
然后,将以下内容添加到位于您的CMakeLists.txt项目中的CLion中(不要忘记使用您获得的路径)。
INCLUDE_DIRECTORIES( /usr/local/Cellar/jsoncpp/1.9.4_1/include )
LINK_DIRECTORIES( /usr/local/Cellar/jsoncpp/1.9.4_1/lib )
file(GLOB LIBRARIES "/usr/local/Cellar/jsoncpp/1.9.4_1/lib/*.dylib")
message("LIBRARIES = ${LIBRARIES}")
TARGET_LINK_LIBRARIES(myProjectName ${LIBRARIES})重新加载CMake (如果不是自动完成的话)。
然后,您可以使用语法在项目文件中使用所需的JSON库:
#include <json/ ... >示例:
#include <json/json.h>
#include <json/value.h>
#include <json/writer.h>
#include <json/reader.h>
...https://stackoverflow.com/questions/34247432
复制相似问题