首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >c++:对“Json::Value::Value”的未定义引用(Json::ValueType)

c++:对“Json::Value::Value”的未定义引用(Json::ValueType)
EN

Stack Overflow用户
提问于 2022-03-09 09:15:06
回答 1查看 1.9K关注 0票数 1

我在ubuntu上安装了jsoncpp和'sudo apt install libjsoncpp-dev‘,并试图运行一个极简的测试程序:

代码语言:javascript
复制
#include <iostream>
#include <fstream>
#include <jsoncpp/json/json.h>

int main()
{
    ifstream file("example.json");
    Json::Value value;
    Json::Reader reader;

    reader.parse(file,value);
    cout << value << endl;
}

我使用makefile来用以下标志编译我的代码:

代码语言:javascript
复制
CC=g++
CXXFLAGS=-std=c++17 -fopenmp -O3 -ljsoncpp

发生下列错误:

代码语言:javascript
复制
/usr/bin/ld: /tmp/cc4MbV6f.o: in function `Test_JsonWriter()':
test.cpp:(.text+0x5865): undefined reference to `Json::Value::Value(Json::ValueType)'
/usr/bin/ld: test.cpp:(.text+0x5872): undefined reference to `Json::Reader::Reader()'
/usr/bin/ld: test.cpp:(.text+0x5885): undefined reference to `Json::Reader::parse(std::istream&, Json::Value&, bool)'
/usr/bin/ld: test.cpp:(.text+0x5894): undefined reference to `Json::operator<<(std::ostream&, Json::Value const&)'
/usr/bin/ld: test.cpp:(.text+0x5a9f): undefined reference to `Json::Value::~Value()'
/usr/bin/ld: /tmp/cc4MbV6f.o: in function `Test_JsonWriter() [clone .cold]':
test.cpp:(.text.unlikely+0x6bf): undefined reference to `Json::Value::~Value()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:21: test] Error 1

我还确保更新所有软件包等等,还包括'#include ‘也没有帮助。

知道是怎么回事吗?谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-09 09:56:54

user17732522的评论解决了我的问题!旗帜放置不当:

"-ljsoncpp必须放在编译器调用上的.cpp文件或.o文件的名称之后“-user17732522

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71406883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档