如何交叉编译具有Yocto Linux库依赖关系的应用程序?

编程入门 行业动态 更新时间:2024-10-28 05:28:02
本文介绍了如何交叉编译具有Yocto Linux库依赖关系的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在笔记本电脑(Ubuntu 14.04)上编写了一个依赖于GStreamer的应用程序,并希望针对我的Yocto Linux目标(iMX6S-Wandboard)对其进行交叉编译.如何交叉编译应用程序,使其在目标板上运行并能够使用GStreamer库?

I wrote an application on my laptop (Ubuntu 14.04) that depends on GStreamer and would like to cross-compile it for my Yocto Linux target (iMX6S-Wandboard). How do I cross-compile the application so that it runs on the target board and is able to use the GStreamer libraries?

谢谢

Toan

UDPATE:

我的Makefile:

My Makefile:

PACKAGES = gstreamer-1.0 override CFLAGS += `pkg-config --cflags $(PACKAGES)` -Wall -Wextra "-DDATADIR=\"$(DATADIR)/\"" -ffunction-sections -fdata-sections override LIBS += `pkg-config --libs $(PACKAGES)` override LDFLAGS += -Wl,--gc-sections OBJS = basic-tutorial-7.o DEPS = $(foreach file,$(OBJS),$(basename $(file)).d) EXE = basic-tutorial-7 DESTDIR ?= PREFIX ?= $(HOME)/.local/ BINDIR ?= $(PREFIX)bin DATADIR ?= $(PREFIX)share/$(PKGNAME) .PHONY : clean install uninstall all: $(EXE) $(EXE) : $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) $(LIBS) $(OBJS) : %.o : %.c %.d @[ -d "$(@D)" ] || mkdir -p "$(@D)" $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< $(DEPS) : %.d : $(PROJECT_ROOT)%.c @[ -d "$(@D)" ] || mkdir -p "$(@D)" $(CC) $(CFLAGS) $(CPPFLAGS) -M -MF $@ -MT "$(basename $@).o" $< clean: rm -fr $(EXE) $(OBJS) $(DEPS) install : $(EXE) install -DT -m 0755 $(EXE) $(DESTDIR)$(BINDIR)/$(EXE) uninstall : rm -v $(DESTDIR)$(BINDIR)/$(EXE) ifneq ($(MAKECMDGOALS), clean) -include $(DEPS) endif

我的* .bb文件:

DESCRIPTION = "Basic Tutorial 7" LICENSE = "CLOSED" LIC_FILES_CHKSUM = "" DEPENDS = "gstreamer1.0 pkgconfig-native gstreamer1.0-plugins-base" FILES_${PN} += "${bindir}/basic-tutorial-7 ${bindir}/basic-tutorial-7" EXTRA_OEMAKE += "DESTDIR=${D}/ DATADIR=${datadir}/basic-tutorial-7 BINDIR=${bindir}" do_compile () { oe_runmake install } do_install () { oe_runmake clean }

构建日志:

$ devtool build basic-tutorial-7 NOTE: Starting bitbake server... NOTE: Reconnecting to bitbake server... NOTE: Retrying server connection (#1)... Loading cache: 100% |############################################| Time: 0:00:00 Loaded 1298 entries from dependency cache. Parsing recipes: 100% |##########################################| Time: 0:00:00 Parsing of 773 .bb files complete (772 cached, 1 parsed). 1299 targets, 63 skipped, 0 masked, 0 errors. Loading cache: 100% |############################################| Time: 0:00:00 Loaded 1298 entries from dependency cache. Parsing recipes: 100% |##########################################| Time: 0:00:00 Parsing of 773 .bb files complete (772 cached, 1 parsed). 1299 targets, 63 skipped, 0 masked, 0 errors. NOTE: Resolving any missing task queue dependencies Initialising tasks: 100% |#######################################| Time: 0:00:01 Sstate summary: Wanted 0 Found 0 Missed 0 Current 322 (0% match, 100% complete) NOTE: Executing Tasks NOTE: Setscene tasks completed NOTE: Tasks Summary: Attempted 1480 tasks of which 1480 didn't need to be rerun and all succeeded.

部署日志:

$ devtool deploy-target basic-tutorial-7 root@192.168.0.101 NOTE: Starting bitbake server... NOTE: Reconnecting to bitbake server... NOTE: Retrying server connection (#1)... Loading cache: 100% |############################################| Time: 0:00:00 Loaded 1298 entries from dependency cache. Parsing recipes: 100% |##########################################| Time: 0:00:00 Parsing of 773 .bb files complete (772 cached, 1 parsed). 1299 targets, 63 skipped, 0 masked, 0 errors. ERROR: No files to deploy - have you built the basic-tutorial-7 recipe? If so, the install step has not installed any files.

推荐答案

Yocto eSDK 允许您使用目标本身使用的编译器和库在PC上交叉编译Yocto目标的应用程序.无需将GCC添加到目标.eSDK可以从Yocto源代码树生成,但是由于无论如何都要安装源代码,因此不需要安装eSDK,并且可以直接从源代码构建.所有这些都不是特定于ARM的,而是通用的Yocto工作流程,可以针对特定的Yocto目标进行交叉编译.

The Yocto eSDK allows you to cross-compile applications for your Yocto target on your PC using exactly the compiler and libraries used for the target itself. There is no need to add GCC to the target. The eSDK can be generated from a Yocto source tree, but since you have the source installed anyways, you don't need to install the eSDK and can build directly from the source. All of the this is not ARM specific but the general Yocto workflow to cross-compile for a specific Yocto target.

为此,请像往常一样先通过转入Yocto目录来设置Yocto构建环境,然后运行 source setup-environment yourbuilddir .

To do this, first setup the Yocto build environment as usual by changing into the Yocto directory, running source setup-environment yourbuilddir.

然后,运行 devtool add ,传递应用程序的名称(将用于BitBake配方)和现有源树的路径,例如:

Then, run devtool add, pass the name of your application (will be used for the BitBake recipe) and the path to the existing source tree, e.g.:

devtool add myhelloworld /home/user/Projects/myhelloworld

这将自动生成一个配方,并在您的Yocto源代码树中添加一个名为 workspace 的图层.该食谱将被命名为/yocto/source/path/yourbuilddir/workspace/recipes/myhelloworld/myhelloworld.bb .您可以通过运行

This will automatically generate a recipe and add a layer named workspace to your Yocto source tree. The recipe will be named something like /yocto/source/path/yourbuilddir/workspace/recipes/myhelloworld/myhelloworld.bb. You can edit it by running

devtool edit-recipe myhelloworld

使用 EDITOR = gedit 之类的命令为命令添加前缀,以使用您喜欢的文本编辑器.修改配方以正确构建您的应用程序;BitBake将自动确定是运行 make 还是 CMake .使用 make 的示例为:

Prefix the command with something like EDITOR=gedit to use your favourite text editor. Modify the recipe to build your application correctly; BitBake will automatically determine whether to run make or CMake. An example using make would be:

DESCRIPTION = "My GStreamer Hello World" LICENSE = "CLOSED" LIC_FILES_CHKSUM = "" DEPENDS = "gstreamer1.0 pkgconfig-native" FILES_${PN} += "${bindir}/myhelloworld ${datadir}/myhelloworld" EXTRA_OEMAKE += "DESTDIR=${D}/ DATADIR=${datadir}/myhelloworld BINDIR=${bindir}" do_install() { oe_runmake install } do_clean() { oe_runmake clean }

DEPENDS 列出了相关性,我添加了 gstreamer1.0 以及 pkgconfig-native ,这在使用 pkg-config时是必需的在 Makefile 中.如果需要,可以向 DEPENDS 添加更多依赖项,例如 boost openssl .合适的示例makefile是:

DEPENDS lists the dependencies, I added gstreamer1.0 and also pkgconfig-native which is neccessary when using pkg-config inside the Makefile. You can add more dependencies to DEPENDS if you need them, for example boost openssl. A suitable example makefile would be:

PACKAGES = gstreamer-1.0 override CFLAGS += `pkg-config --cflags $(PACKAGES)` -Wall -Wextra "-DDATADIR=\"$(DATADIR)/\"" -ffunction-sections -fdata-sections override LIBS += `pkg-config --libs $(PACKAGES)` override LDFLAGS += -Wl,--gc-sections OBJS = main.o DEPS = $(foreach file,$(OBJS),$(basename $(file)).d) EXE = myhelloworld DESTDIR ?= PREFIX ?= $(HOME)/.local/ BINDIR ?= $(PREFIX)bin DATADIR ?= $(PREFIX)share/$(PKGNAME) .PHONY : clean install uninstall all: $(EXE) $(EXE) : $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) $(LIBS) $(OBJS) : %.o : %.c %.d @[ -d "$(@D)" ] || mkdir -p "$(@D)" $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< $(DEPS) : %.d : $(PROJECT_ROOT)%.c @[ -d "$(@D)" ] || mkdir -p "$(@D)" $(CC) $(CFLAGS) $(CPPFLAGS) -M -MF $@ -MT "$(basename $@).o" $< clean: rm -fr $(EXE) $(OBJS) $(DEPS) install : $(EXE) install -DT -m 0755 $(EXE) $(DESTDIR)$(BINDIR)/$(EXE) uninstall : rm -v $(DESTDIR)$(BINDIR)/$(EXE) ifneq ($(MAKECMDGOALS), clean) -include $(DEPS) endif

在您的 Makefile 内,确保 make install 将应用程序二进制文件安装到 $(DESTDIR)$(BINDIR)/myhelloworld 和数据中文件(例如图像)到 $(DESTDIR)$(DATADIR)/somefile 中.在目标上,您的二进制文件将位于/usr/bin/myhelloworld 中,数据文件位于/usr/share/myhelloworld 中.在 Makefile 中,将-DDATADIR = \" $(DATADIR)/\" 传递给编译器,这样您就可以通过fopen(DATADIR"somepic.png","rb"); .对于源文件 main.c ,您可以使用 GStreamer示例1 .

Inside your Makefile, make sure that make install installs your application binary into $(DESTDIR)$(BINDIR)/myhelloworld and data files (e.g. images) into $(DESTDIR)$(DATADIR)/somefile. On the target, your binary will then be located in /usr/bin/myhelloworld and the data files in /usr/share/myhelloworld. In the Makefile, pass "-DDATADIR=\"$(DATADIR)/\"" to the compiler such that you can open your data files by something like fopen(DATADIR "somepic.png", "rb");. For the source file main.c, you can use the GStreamer example 1.

保存配方, Makefile 和 main.c ,然后运行

Save recipe, Makefile and main.c, and then run

devtool build myhelloworld

编译您的应用程序.如果一切顺利,您可以运行以下命令通过SSH将其安装到目标.

to compile your application. If all goes well, you can then install it to the target via SSH by running e.g.

devtool deploy-target myhelloworld root@targethostname

然后您可以通过键入 myhelloworld SSH到目标并运行您的应用程序.要卸载它:

You can then SSH to the target and run your application by typing myhelloworld. To uninstall it:

devtool undeploy-target myhelloworld root@targethostname

如果您以后决定将应用程序作为Yocto映像的一部分提供,请修改系统映像的配方并添加:

If you later decide to ship your application as part of the Yocto image, modify the recipe for your system image and add:

IMAGE_INSTALL_append = " yourhelloworld"

在第一引号后保留空格.构建映像时,将包括您的应用程序和数据.这种方法(使用BitBake配方)的主要优点是将应用程序添加到映像变得容易,并且该应用程序将与目标上可用的库完全链接,因此您可以完全使用这些版本中存在的功能

Keep the space after the first quote. When building the image, your application and data will be included. The main advantage of this approach (using a BitBake recipe) is that adding the application to the image becomes easy, and that the application will be linked against exactly the libraries available on the target, so you can use exactly the features present in these versions.

使用上面的示例makefile,您还可以通过简单地运行 make 来直接为您的主机PC编译.

Using the example makefile above, you can also directly compile for your host PC by simply running make.

更多推荐

如何交叉编译具有Yocto Linux库依赖关系的应用程序?

本文发布于:2023-07-27 14:21:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222832.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   关系   Yocto   Linux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!