2017-03-28 63 views
1

每個搜索如何在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中的靜態庫?

回答

1

追加您的添加示例。

添加以下行到圖像的食譜(或一個.bbappend,如core-image-minimal.bbappend

TOOLCHAIN_TARGET_TASK += "example-staticlib-staticdev" 

應該爲你工作。這會在運行bitbake core-image-minimal -c populate_sdk之後爲您提供SDK中的.a文件。 (再次假設使用的圖像是core-image-minimal)。

.a文件添加到${PN}-dev的實驗不起作用,它與文件如何放入包中的順序相同。訂單是${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}。因此,無論如何,.a文件將被放入${PN}-staticdev,因爲該包在{PN}-dev之前處理。

請注意,您將此行TOOLCHAIN_TARGET_TASK += "example-staticlib-staticdev"添加到您的圖像配方中,因此,您需要編寫包名稱而不是PN

+0

是的,刪除你有兩條線。 '.a'文件被'$ {PN} -staticdev'包自動拾取。 – Anders

+0

查看我的補充說明。 – Anders

+0

在我最後的評論之前查看我的答案。您需要在圖像配方上添加工具鏈變量n。 – Anders