0

I wrote a recipe to compile a git repo in Yocto. The repository contains a Makefile to compile the code. 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. 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

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

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.

2 Answers2

0

The Makefile should have CXXFLAGS and LDFLAGS used instead of the hardcoded 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.

If I can suggest, using meson, autotools or cmake might get you further quicker than writing Makefille by hand.

qschulz
  • 1,543
  • 1
  • 9
  • 10
0

What is the output of the command pkg-config --cflags --libs jsoncpp? If you run it from Yocto what does it print? You can ask your makefile itself to print this info, by adding something like this to the makefile:

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

Likely it will print something including the flag -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.

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.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • This is a reasonable answer but note that Yocto is a cross compile system and running pkg-config on the build host shell will give different results than the pkg-confg that gets used during build – Jussi Kukkonen Jan 03 '21 at 15:15
  • Yes, true: you need to run the `pkg-config` in the same environment where make is invoked. – MadScientist Jan 03 '21 at 15:23