简体   繁体   English

如何将 jsoncpp 库包含到 unix 上的项目中?

[英]How to include jsoncpp library into project on unix?

The library I am trying to include is jsoncpp .我要包含的库是jsoncpp I am having serious trouble with this.我遇到了严重的麻烦。 I used the home-brew install for this library, which is brew install jsoncpp ( brew install is unix version of linux sudo-apt get ).我为这个库使用了自制软件安装,即brew install jsoncppbrew install是 unix 版本的 linux sudo-apt get )。 Normally homebrew installs stuff to my path, so I can just use it.通常homebrew会在我的路径中安装东西,所以我可以直接使用它。 I am going off of this example here.我在这里结束这个例子

#include <json/json.h>

Returns an error of 10: fatal error: 'json/value.h' file not found .返回错误10: fatal error: 'json/value.h' file not found

I am using cmake because CLion automatically sets it up.我使用的是 cmake,因为 CLion 会自动设置它。 Right now it is very basic:现在它是非常基本的:

#CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
project(Read_JSON)

set(CMAKE_CXX_STANDARD 17)

add_executable(Read_JSON main.cpp)

However, for some reason jsoncpp cannot be found.但是,由于某种原因, jsoncpp How can I include this library in my project?我如何将这个库包含在我的项目中?

You can use in CMake FetchContent capability.您可以在 CMake FetchContent 功能中使用。 Jsoncpp is available via git repository on GitHub Jsoncpp 可通过 GitHub 上的 git 存储库获得

Here is example how I made with googletest: https://github.com/adamvm/hello/blob/master/CMakeLists.txt这是我如何使用 googletest 制作的示例: https : //github.com/adamvm/hello/blob/master/CMakeLists.txt

You need just substitute proper addresses and names您只需要替换正确的地址和名称

On mac install with command.在 mac 上使用命令安装。

brew install osrf/simulation/ignition-fuel-tools2 brew install osrf/simulation/ignition-fuel-tools2

In Ubuntu (since 18.04) you need to install libjsoncpp-dev [1] package:在 Ubuntu(自 18.04 起)需要安装libjsoncpp-dev [1] package:

sudo apt install libjsoncpp-dev

[1] https://packages.ubuntu.com/search?keywords=libjsoncpp-dev [1] https://packages.ubuntu.com/search?keywords=libjsoncpp-dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM