如何让 gps.h 进入 Yocto 配方构建?

How to get gps.h into a Yocto recipe build?

我已经建立了一个简单的食谱,只要我不需要就可以使用 gps.h:

recipes/foo (dunfell) $ cat foo_3.0.0.bb 
DESCRIPTION = "FOO Daemon"
LICENSE = "CLOSED"

SRC_URI = " file://*.* \
    "
S = "${WORKDIR}"

INSANE_SKIP_${PN} = "ldflags"
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
INHIBIT_PACKAGE_STRIP = "1"

do_compile() {
    cd ${S}/src
    make
    cp foo ~/
    cd -
}

do_install() {
    install -d ${D}${bindir}
    install -m 0755 foo ${D}${bindir}
}

gps.h 在我本地机器上的 /usr/include 中,但是 Yocto 是 cross-compiling 它提供了为什么它不能使用本地 /usr/include/gps.h 的合理解释:

cc1: error: include location "/usr/include" is unsafe for cross-compilation [-Werror=poison-system-directories]
foo.c:54:10: fatal error: gps.h: No such file or directory
   54 | #include <gps.h>
      |          ^~~~~~~
cc1: all warnings being treated as errors

我已经在我的 layer.conf 中尝试了 IMAGE_INSTALL_append " libgps-dev"" gps-lib-dev",但这些都不起作用。

如何在构建时将 gps.h header 放入我的 Yocto project/recipe?

让我复制你的食谱并先添加一些评论:

DESCRIPTION = "FOO Daemon"
LICENSE = "CLOSED"

# --- COMMENT ---
# It is not recommended to use "*" with SRC_URI, 
# as Yocto will not keep track of your files if you edit them 
# so it will never rebuild automaticall after a change
# Best practice is to sepecify the local files like:
# SRC_URI = "file://src"
# This will make bitbake unpacks the "src" folder into ${WORKDIR}
# --- COMMENT ---
SRC_URI = " file://*.* \
    "

# --- COMMENT ---
# The ${S} variable is the defautl workind directory for compilation tasks, 
# do_configure, do_compile, ..., 
# So, if you have "src" folder that will be unpacked into ${WORKDIR}
# you need to set S to that:
# S = "${WORKDIR}/src"
# --- COMMENT ---
S = "${WORKDIR}"

INSANE_SKIP_${PN} = "ldflags"
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
INHIBIT_PACKAGE_STRIP = "1"

# --- COMMENT ---
# If your project has a "Makefile" you can use the "autotools" class
# it runs oe_runmake automatically
# inherit autotools
# If you want to copy the output to your home directory you can do it in "do_install"
# If you use autotools you do not need do_compile
# --- COMMENT ---
do_compile() {
    cd ${S}/src
    make
    cp foo ~/
    cd -
}

do_install() {
    install -d ${D}${bindir}
    install -m 0755 foo ${D}${bindir}
}

# --- COMMENT ---
# Do not forget to specify your output files into FILES for do_package to work well
# FILES_${PN} = "${bindir}/foo"
# --- COMMENT ---

现在,在处理完这些之后,如果您的配方需要 build-time 中的内容,则依赖项需要存在于同一配方的工作目录中,因为如果您将 libgps 添加到 IMAGE_INSTALL 中将出现在 rootfs 中,但不会出现在您的构建期间。

因此,为此,您需要使用 DEPENDS 指定依赖项配方。

我找过 gps.h,我发现它与 gpsd 食谱打包在一起。

所以,尝试:

DEPENDS += "gpsd"

所以,最终的配方如下所示:

DESCRIPTION = "FOO Daemon"
LICENSE = "CLOSED"

SRC_URI = "file://src"

S = "${WORKDIR}/src"

DEPENDS += "gpsd"

inherit autotools

do_install(){
    install -d ${D}${bindir}
    install -m 0755 foo ${D}${bindir}
    cp foo ~/
}

FILES_${PN} = "${bindir}/foo"

只剩下测试了