Search code examples
yoctobitbake

bitbake fail, cannot find .cpp file


This is my .bb file, I already git clone the repo at /home/chtan/rcu-service

SUMMARY = "RCU Service"
DESCRIPTION = "Recipe to install RCU Service into RCU image"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

inherit systemd
SYSTEMD_AUTO_ENABLE = "enable"
SYSTEMD_SERVICE_${PN} = "rcu-service.service"

inherit externalsrc
EXTERNALSRC = "/home/chtan/rcu-service"
EXTERNALSRC_BUILD = "${EXTERNALSRC}"


FILES_${PN} += "${systemd_unitdir}/system/rcu-service.service"
S = "${WORKDIR}"

TARGET_CC_ARCH += "${LDFLAGS}"

do_compile() {
         ${CXX} rcu-service.cpp -o rcu-service
}

do_install() {
         install -d ${D}${bindir}
         install -m 0755 rcu-service ${D}${bindir}
         install -d ${D}/${systemd_unitdir}/system
         install -m 0644 ${WORKDIR}/git/rcu-service.service ${D}/${systemd_unitdir}/system
}
enter code here

However, it fail during bitbake, please refer to syntax at below

2021-02-04T16:26:47.6181432Z aarch64-tdx-linux-g++: error: rcu-service.cpp: No such file or directory

2021-02-04T16:26:55.9000799Z Summary: 1 task failed:

2021-02-04T16:26:55.9001769Z /__w/1137/s/build/../layers/meta-smartracks/recipes-core/rcu-service/rcu-service_1.0.bb:do_compile

My files(rcu-service.cpp , rcu-service.service) are located at /home/chtan/rcu-service What Syntax should I add in my .bb file in order to let compiler reaches my file ?


Solution

  • You must change your do_compile build step as this for this to work.

    do_compile() {
              ${CXX} ${S}/rcu-service.cpp -o rcu-service
    }
    

    In do_install you should change ${WORKDIR}/git/rcu-service.service to ${S}/git/rcu-service.service

    Extract from the yocto project manual
    By default, the OpenEmbedded build system uses the S and B variables to locate unpacked recipe source code and to build it, respectively. When your recipe inherits the externalsrc class, you use the EXTERNALSRC and EXTERNALSRC_BUILD variables to ultimately define S and B.

    So in your case S and B will have the following values

    S="/home/chtan/rcu-service"
    B="/home/chtan/rcu-service"
    

    Note you dont need to set ${WORKDIR}/rcu-service since the command dir is already ${WORKDIR} you could check this by adding the following line

    bbwarn $(pwd) 
    

    in your do_compile task.

    You should also remove the following line since it gets overwriten by the externalsrc.bbclass

    S = "${WORKDIR}"