jsoncpp链接错误cmake

Mic*_*mer 2 c++ eclipse cmake linker-errors jsoncpp

我是 cmake 的新手。它工作得很好,但现在我遇到一些链接错误:

undefined reference to `Json::Reader::Reader()'
undefined reference to `Json::Value::Value(Json::ValueType)'
undefined reference to `Json::Reader::parse(std::basic_istream<char, std::char_traits<char> >&, Json::Value&, bool)'
undefined reference to `google::protobuf::MessageLite::ParseFromArray(void const*, int)'
Run Code Online (Sandbox Code Playgroud)

还有更多这样的类型。

我想我必须在某个地方添加 jsoncpp 库。

这里有人知道如何做到这一点吗?

arr*_*owd 5

target_link_libraries(your_exe_target_name jsoncpp)
Run Code Online (Sandbox Code Playgroud)

确保您已link_directories()预先设置。

  • [`link_directories`](http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:link_directories) 不是提供 CMake 路径的好方法 - 它自己的文档不鼓励使用它。最好使用 [`find_library`](http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_library) 并将完整路径传递到 `target_link_libraries` (2认同)