Yocto gcc无法从共享库中找到对函数的引用

时间:2017-04-27 15:31:07

标签: include cross-compiling yocto bitbake

我编写了一个包含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",我的error: undefined reference to函数也来自foo.h。这是我的测试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


为什么?谢谢你的帮助!

1 个答案:

答案 0 :(得分:3)

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

这应该是

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

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

你还应该删除FILES_ {PN}行:它是错误的(因为标题进入-dev包)而不需要,因为默认情况下应该正确完成。