【问题标题】:Yocto gcc cannot find reference to function from shared libraryYocto gcc 无法从共享库中找到对函数的引用
【发布时间】:2017-09-25 12:00:37
【问题描述】:

我编写了一个包含 3 个文件的包:foo.c、foo.h 和 README.TXT。这是食谱:

DESCRIPTION = "foo Drivers"
#To prevent the LICENSE field not set
LICENSE = "CLOSED"
PR = "r0"

SRC_URI = "file://foo.c \
       file://foo.h \
           file://README.txt"

FILES_${PN} += "${incdir}/foo.h"

do_compile() {
        ${CC} ${CFLAGS} ${LDFLAGS} ${WORKDIR}/foo.c -o foo
}

do_install() {
        install -m 0755 -d ${D}${bindir} ${D}${docdir}/foo ${D}${incdir}
        install -m 0755 ${S}/foo ${D}${bindir}
        install -m 0755 ${WORKDIR}/README.txt ${D}${docdir}/foo
        install -m 0755 ${WORKDIR}/foo.h ${D}${incdir}
}

但是当我做bitbake foo 时,我有这个错误:

WARNING: foo-0.0-r0 do_package: QA Issue: foo: Files/directories were installed but not shipped in any package:
  /foo.h
Please set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install.
foo: 1 installed and not shipped files. [installed-vs-shipped]

因此,在另一个依赖于 foo 的包中,当我添加配方时:DEPENDS = "foo",我有这个错误:

fatal error: foo.h: No such file or directory

错误来自#include <foo.h> 行。

感谢您的帮助!

编辑:

install -m 0755 ${WORKDIR}/foo.h ${D}${includedir}

解决了警告问题,但我仍然有:

fatal error: foo.h: No such file or directory

当我想根据 foo.h 编译一个包时

EDIT2: 我已经更改了我的 foo 包的 bblayer 以创建一个 .so 共享库,如下所示:

DESCRIPTION = "foo driver"
#To prevent the LICENSE field not set
LICENSE = "CLOSED"
PR = "r70"

SRC_URI = "file://foo.c \
           file://foo.h \
           file://README.txt"

CFLAGS_append =" -fPIC -g -c -Wall "

FILES_${PN} += "${libdir}/* ${libdir}/pkgconfig/*"

do_compile() {
    ${CC} ${CFLAGS} ${LDFLAGS} ${WORKDIR}/foo.c -o foo
    ${CC} -shared -Wl,-soname,${WORKDIR}/libfoo.so.1 \
        -o ${WORKDIR}/libfoo.so.1.0.1 foo -lc

}

do_install() {

    install -m 0755 -d ${D}${bindir} ${D}${libdir} ${D}${docdir}/foo ${D}${includedir} ${D}${libdir}/pkgconfig
    install -m 0755 ${S}/foo ${D}${bindir}
    install -m 0755 ${WORKDIR}/README.txt ${D}${docdir}/foo
    install -m 0755 ${WORKDIR}/foo.h ${D}${includedir}
    install -m 0755 ${WORKDIR}/libfoo.so.1.0.1 ${D}${libdir}
    ldconfig -n ${D}${libdir}
}

但是在我的测试包中,即使我添加了#include <foo.h>DEPENDS = "pjproject gpio" RDEPENDS_${PN} += "gpio",我也有来自foo.herror: undefined reference to 函数。这是我的测试bblayer:

DESCRIPTION = "test"
LICENSE = "CLOSED"

PR = "r2"

SRC_URI = "file://main.c \
           file://Makefile \
           file://README.txt"

S = "${WORKDIR}/"

DEPENDS = "gpio"
RDEPENDS_${PN} += "gpio"


do_compile() {
        cd ${S}
        oe_runmake
}

do_install() {
        install -m 0755 -d ${D}${bindir} ${D}${docdir}/test
        install -m 0755 ${S}/test ${D}${bindir}
        install -m 0755 ${WORKDIR}/README.txt ${D}${docdir}/test
}

如果我在我的 Makefile 中添加-lfoo,我就有/bin/sh: 1: -lfoo: not found


为什么?谢谢你的帮助!

【问题讨论】:

    标签: include cross-compiling yocto bitbake


    【解决方案1】:
    install -m 0755 ${WORKDIR}/foo.h ${D}${incdir}
    

    这应该是

    install -m 0755 ${WORKDIR}/foo.h ${D}${includedir}
    

    您可以在 QA 警告消息中看到您的标头是如何安装到 / 而不是 /usr/include/ 的。

    您还应该删除 FILES_{PN} 行:这是错误的(因为标头进入 -dev 包)并且不需要,因为默认情况下应该做正确的事情。

    【讨论】:

    • 谢谢,${D}${includedir} 是我的bitbake foo 问题的解决方案。但我还有fatal error: foo.h: No such file or directory...
    • 有什么想法吗?对于我剩下的问题?
    • 在帖子中看不到任何错误...我会看看实际的编译输出(应该在 $WORKDIR/temp/log.do_compile 中)——它是否有目标sysroot 作为包含目录。我还会查看 sysroot 目录并仔细检查头文件是否已安装在其中。在 yocto master 上,sysroot 位于 $WORKDIR/recipe-sysroot/ 中(它是专门为此配方构建的),但在旧版本中,它们位于 $TMPDIR/sysroots// 中(这些是所有配方共享的通用 sysroot)。
    • 谢谢,即使我将install -m 0755 ${WORKDIR}/foo.h ${D}${includedir} 更改为install -m 0755 ${WORKDIR}/foo.h ${D}/usr/include,我也必须添加#include <linux/foo.h> 而不是#include <foo.h>,但我遇到了链接器问题。我有error: undefined reference to foo.h 中的所有函数,我在 main.c 中调用...
    • soo foo.h 公开函数?你知道你的食谱没有安装任何库吗?
    猜你喜欢
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 2023-02-25
    • 2023-02-09
    • 1970-01-01
    • 1970-01-01
    • 2020-03-12
    相关资源
    最近更新 更多