每個搜索如何在SDK中包含靜態庫的人都肯定讀了this thread from 2014。我嘗試了他們的建議,但那並不奏效。如何在sdk中獲取靜態庫?
閱讀yocto mega手冊2.1版(yocto morty),我在章節5.9.12中找到。 (Poky Reference Distribution Changes),他們添加了DISABLE_STATIC變量,來禁止生成靜態庫。我嘗試添加這我的食譜,並沒有能夠添加靜態庫SDK:
DISABLE_STATIC = ""
建設中的形象時,我可以看到庫中SYSROOT。但它沒有進入SDK。
那麼,我需要做什麼才能獲得靜態庫和SDK中的頭文件?
什麼工作是添加staticdev包'IMAGE_INSTALL'在local.conf
,但我不希望有這樣做。
我創建了一個示例配方,它演示了我的問題。目錄結構是這樣的:
example-staticlib/
example-staticlib/example-staticlib_0.1.bb
example-staticlib/files/
example-staticlib/files/lib.c
example-staticlib/files/lib.h
example-staticlib/files/Makefile
example-staticlib_0.1.bb:
DESCRIPTION = "example stared library"
LICENSE = "LGPLv2"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/LGPL-2.0;md5=9427b8ccf5cf3df47c29110424c9641a"
SRC_URI = "file://lib.c \
file://lib.h \
file://Makefile"
PR = "r0"
S = "${WORKDIR}"
ALLOW_EMPTY_${PN} = "1"
do_install() {
oe_runmake install DEST=${D}
}
TOOLCHAIN_TARGET_TASK += "example-staticlib-dev"
TOOLCHAIN_TARGET_TASK += "example-staticlib-staticdev"
lib.c:
int foo()
{
return 42;
}
lib.h:
int foo();
Makefile:
TARGET=libexample.a
all:$(TARGET)
install :
@install -d $(DEST)/usr/lib/
@install -m 0644 $(TARGET) $(DEST)/usr/lib/
@install -d $(DEST)/usr/include/
@install -m 0644 lib.h $(DEST)/usr/include/
$(TARGET) : lib.c
$(CC) -c lib.c -o lib.o
$(AR) rcs [email protected] lib.o
clean:
rm -rf lib.o $(TARGET)
如何修改配方,以獲得SDK中的靜態庫?
是的,刪除你有兩條線。 '.a'文件被'$ {PN} -staticdev'包自動拾取。 – Anders
查看我的補充說明。 – Anders
在我最後的評論之前查看我的答案。您需要在圖像配方上添加工具鏈變量n。 – Anders