2016-06-08 156 views
-3

我正在研究yocto,我想在yocto中編譯一些c文件並將它們安裝到外部文件系統。 在此之前,我試着創建一個單獨的reciepe並從它編譯c代碼。 我無法編譯它。如何在yocto中編譯基本c文件

+1

請發佈[最小,完整和可驗證示例](http:// stackov erflow.com/help/mcve)。 – MikeCAT

+1

好的,感謝您分享您的問題,您是否也有具體問題? –

回答

8

我不確定要理解這個問題,因爲它不夠精確。

包括配方樹C文件

如果你想在你的食譜的C文件,其文件樹這樣的:

recipe-example/example/example_0.1.bb 
recipe-example/example/example-0.1/helloworld.c 

當你創建一個新的可以產生這個例子層使用

yocto-layer <your-layer-name> 

你的BB文件將是這樣的:

# 
# This file was derived from the 'Hello World!' example recipe in the 
# Yocto Project Development Manual. 
# 
SUMMARY = "Simple helloworld application" 
SECTION = "examples" 
LICENSE = "MIT" 
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" 

SRC_URI = "file://helloworld.c" 

S = "${WORKDIR}" 

do_compile() { 
     ${CC} helloworld.c -o helloworld 
} 

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

它將編譯hello world文件並將其安裝到映像的/ usr/bin中。

從一個Git回購

您也可以從一個Git倉庫編譯,我建議你閱讀在你的文件夾yocto手冊和示例。下面是這裏wiringPi的示例:

DESCRIPTION = "A library to control Raspberry Pi GPIO channels" 
HOMEPAGE = "https://projects.drogon.net/raspberry-pi/wiringpi/" 
SECTION = "devel/libs" 
LICENSE = "LGPLv3+" 
LIC_FILES_CHKSUM = "file://COPYING.LESSER;md5=e6a600fd5e1d9cbde2d983680233ad02" 

# tag 2.29 
SRCREV = "d79506694d7ba1c3da865d095238289d6175057d" 

S = "${WORKDIR}/git" 

SRC_URI = "git://git.drogon.net/wiringPi \ 
      file://0001-Add-initial-cross-compile-support.patch \ 
      file://0001-include-asm-ioctl.h-directly-for-_IOC_SIZEBITS.patch \ 
      " 

COMPATIBLE_MACHINE = "raspberrypi" 

CFLAGS_prepend = "-I${S}/wiringPi -I${S}/devLib" 

EXTRA_OEMAKE += "'INCLUDE_DIR=${D}${includedir}' 'LIB_DIR=${D}${libdir}'" 
EXTRA_OEMAKE += "'DESTDIR=${D}/usr' 'PREFIX=""'" 

do_compile() { 
    oe_runmake -C devLib 
    oe_runmake -C wiringPi 
    oe_runmake -C gpio 'LDFLAGS=${LDFLAGS} -L${S}/wiringPi -L${S}/devLib' 
} 

do_install() { 
    oe_runmake -C devLib install 
    oe_runmake -C wiringPi install 
    oe_runmake -C gpio install 
} 

它是從一個git倉庫取出,施加由GIT中產生的貼劑,使用oe_runmake與生成文件進行編譯。

隨着devtool

有人問如何添加配方與devtool評論。 我們仍然會使用wiringPi作爲例子。下載它做 https://github.com/WiringPi/WiringPi Makefile是文件夾wiringPi。 然後,您可以做

devtool add <name_of_recipe> <path_to_Makefile_folder> 

小心的警告從devtool

NOTE: Creating workspace layer in /home/dbensoussan/new_poky/poky/build/workspace 
NOTE: Enabling workspace layer in bblayers.conf 
NOTE: Using source tree as build directory since that would be the default for this recipe 
NOTE: Recipe /home/dbensoussan/new_poky/poky/build/workspace/recipes/project/project.bb has been automatically created; further editing may be required to make it fully functional 

這是生成的配方如下:

# Recipe created by recipetool 
# This is the basis of a recipe and may need further editing in order to be fully functional. 
# (Feel free to remove these comments when editing.) 
# 
# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is 
# your responsibility to verify that the values are complete and correct. 
LICENSE = "Unknown" 
LIC_FILES_CHKSUM = "file://COPYING.LESSER;md5=e6a600fd5e1d9cbde2d983680233ad02" 

# No information for SRC_URI yet (only an external source tree was specified) 
SRC_URI = "" 


# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the 
# recipe automatically - you will need to examine the Makefile yourself and ensure 
# that the appropriate arguments are passed in. 

do_configure() { 
    # Specify any needed configure commands here 
    : 
} 

do_compile() { 
    # You will almost certainly need to add additional arguments here 
    oe_runmake 
} 

do_install() { 
    # This is a guess; additional arguments may be required 
    oe_runmake install 'DESTDIR=${D}' 
} 

然後,您可以編輯你的食譜,以滿足您配置

+0

如果可能,你可以通過'devtool'演示怎麼做?謝謝。我仍然需要一些關於如何使用它的信息。 –

+1

@CharlesChau,我剛剛編輯了我的答案,並添加了一個devtool –

+0

的例子嗨大衛Bensoussan,感謝您的回答,我使用上面提到的食譜示例。當我執行bitbake -b /PATH_TO_BB/example_0.1.bb它正在生成一個可執行文件。當我運行bitbake core-image-minimal時,它不會編譯任何文件,我是否需要對此進行任何額外的更改 – anikhan