简体   繁体   English

如何使用 jsoncpp 库在 yocto 中编译 git 存储库?

[英]how to compile a git repo in yocto with jsoncpp libary?

I wrote a recipe to compile a git repo in Yocto.我写了一个配方来在 Yocto 中编译一个 git repo。 The repository contains a Makefile to compile the code.该存储库包含用于编译代码的 Makefile。 The first time I was able to compile the code in Yocto, but when I added the jsoncpp library in my code, Yocto not able to compile it.我第一次能够在 Yocto 中编译代码,但是当我在代码中添加 jsoncpp 库时,Yocto 无法编译它。 It is showing some error like它显示了一些错误,例如

test_1.cpp:5:10: fatal error: jsoncpp/json/json.h: No such file or directory
|     5 | #include <jsoncpp/json/json.h>
|       |          ^~~~~~~~~~~~~~~~~~~~~

Here is my recipe file.这是我的食谱文件。 Please suggest me the change I need to done to compile the code.请建议我编译代码所需的更改。

yocto_test.bb yocto_test.bb

SUMMARY = "Hello World"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
DEPENDS = "jsoncpp"

SRCREV = "90052737ee51abca69a334a9208e2fec82d78c19"
SRC_URI = " \
    git://github.com/arghyaBiswas05/yocto-test.git \
    "

S = "${WORKDIR}/git/"

do_compile() {
    oe_runmake all
}

# Install binary to final directory /usr/bin
do_install() {
    install -d ${D}${bindir}
    install -m 0755 ${S}test_file ${D}${bindir}
}

Here is my Makefile这是我的Makefile

all:
    ${CXX} test_1.cpp -o test_file $(shell pkg-config --cflags --libs jsoncpp)

install:
    cp test_file /usr/bin

clean:
    rm -rf test_file

Please suggest me the change.请建议我改变。

The Makefile should have CXXFLAGS and LDFLAGS used instead of the hardcoded JSONLIB . Makefile 应该使用CXXFLAGSLDFLAGS而不是硬编码的JSONLIB Those two variables are accordingly set by Yocto and are required to be able to find files provided by the recipes you have in DEPENDS .这两个变量由 Yocto 相应地设置,并且需要能够找到DEPENDS中的食谱提供的文件。

If I can suggest, using meson, autotools or cmake might get you further quicker than writing Makefille by hand.如果我可以建议,使用介子、autotools 或 cmake 可能比手动编写 Makefille 更快。

What is the output of the command pkg-config --cflags --libs jsoncpp ?命令pkg-config --cflags --libs jsoncpp什么? If you run it from Yocto what does it print?如果你从 Yocto 运行它,它会打印什么? You can ask your makefile itself to print this info, by adding something like this to the makefile:您可以要求您的 makefile 本身打印此信息,方法是在 makefile 中添加类似这样的内容:

$(info args: $(shell pkg-config --cflags --libs jsoncpp))

Likely it will print something including the flag -I/usr/include/jasoncpp .它可能会打印一些内容,包括标志-I/usr/include/jasoncpp If it does then your #include is wrong, because a -I of /usr/include/jasoncpp plus an include of jasoncpp/json/json.h gives a full path of /usr/include/jasoncpp/jasoncpp/json/json.h and that file clearly doesn't exist.如果是这样,那么您的#include是错误的,因为/usr/include/jasoncpp-I加上jasoncpp/json/json.h的包含会给出/usr/include/jasoncpp/jasoncpp/json/json.h并且该文件显然不存在。

I think most likely your include should be #include <json/json.h> but there's no way to know for sure without knowing how the jsoncpp package is installed, where it puts its headers, and what flags it expects.我认为您的 include 很可能应该是#include <json/json.h>但是如果不知道jsoncpp package 是如何安装的、它放置标题的位置以及它期望的标志,就无法确定。

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

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