繁体   English   中英

如何调用在yocto的另一层中定义的C函数?

[英]how to call a C function which is defined in another layer of yocto?

我已按照网站中提供的说明进行操作:

https://wiki.yoctoproject.org/wiki/Building_your_own_recipes_from_first_principles

我已经通过构建我自己的层成功地刷新了 yocto 图像。 但我的问题是:

是否可以创建两个层,即第 1 层和第 2 层? 第 1 层包含 C 程序。

SimpleLibrary.c

#include<stdio.h>

int add_numbers(int a, int b)
{
    return a+b;
}

第 1 层必须提供此库 (.so) 以便第 2 层可以使用提到的函数 (add_numbers) 。

第 2 层我有 ac 程序,它将调用第 1 层中的函数

#include <stdio.h>

int main()
{
    int a = 2, b = 3;

    int sum = add_numbers(a, b);
    printf("%d",sum);
}

如果可能,如何编译第 1 层、第 2 层以及我应该在这两层的 conf 文件中进行哪些更改?

使用以下命令为 SimpleLibrary.c 和 .h 文件创建库配方

...

SRC_URI := " \
        file://SimpleLibrary.c  \
        file://SimpleLibrary.h  \
        "

S = "${WORKDIR}/"

PACKAGES = "${PN} ${PN}-dev ${PN}-dbg ${PN}-staticdev"

RDEPENDS_${PN}-staticdev = ""
RDEPENDS_${PN}-dev = ""
RDEPENDS_${PN}-dbg = ""

do_compile() {
             ${CC} *.c -c
             ${AR} rcs libSimpleLibrary.a *.o
}

do_install() {
             install -d ${D}${libdir}
             install -m 0644 libSimpleLibrary.a ${D}${libdir}
}

TARGET_CC_ARCH += "${LDFLAGS}"

然后对于应用程序使用以下

FILESEXTRAPATHS_prepend := "${THISDIR}<path to the simple Library header file>:"

SRC_URI = "file://app.c \
           file://SimpleLibrary.h \ 
        "

S = "${WORKDIR}/"

DEPENDS = "SimpleLibrary"

do_compile() {
             ${CC} *.c -o app -lSimpleLibrary
}

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

TARGET_CC_ARCH += "${LDFLAGS}"

或者基本上,当您添加 DEPENDS = "SimpleLibrary" 时。 您的库的头文件将被提取到应用程序的暂存目录中。 因此,您可以包含它们并毫无问题地编译

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM