如何将我自己的软件添加到 Buildroot Linux 软件包中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19783795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add my own software to a Buildroot Linux package?
提问by AlexandruC
I am trying to add my own program to a small linux, created with Buildroot. What I've done so far:
我正在尝试将我自己的程序添加到使用 Buildroot 创建的小型 linux 中。到目前为止我所做的:
I've created a new directory inside my 'buildroot/package/' called 'HelloWorld'. Inside 'buildroot/package/HelloWorld' I have : a Config.in, HelloWorld.mk and HelloWorld directory. Config.inholds this:
config BR2_PACKAGE_HELLOWORLD bool "helloworld" default y help Hello world component.
我在“buildroot/package/”中创建了一个名为“HelloWorld”的新目录。在“buildroot/package/HelloWorld”中,我有:一个 Config.in、HelloWorld.mk 和 HelloWorld 目录。 Config.in持有这个:
config BR2_PACKAGE_HELLOWORLD bool "helloworld" default y help Hello world component.
HelloWorld.mk holds this:
HelloWorld.mk 持有这个:
HELLOWORLD_VERSION:= 1.0.0
HELLOWORLD_SITE:= /home/userpc/Downloads/helloworld/
HELLOWORLD_SITE_METHOD:=local
HELLOWORLD_INSTALL_TARGET:=YES
define HELLOWORLD_BUILD_CMDS
$(MAKE) CC="$(TARGET_CC)" LD="$(TARGET_LD)" -C $(@D) all
endef
define HELLOWORLD_INSTALL_TARGET_CMDS
$(INSTALL) -D -m 0755 $(@D)/helloworld $(TARGET_DIR)/bin
endef
define HELLOWORLD_PERMISSIONS
/bin/helloworld f 4755 0 0 - - - - -
endef
$(eval $(generic-package))
(inspiration source) The HelloWorld directory contains: main.c & Makefile:
(灵感来源) HelloWorld 目录包含: main.c & Makefile:
main.c :
主文件:
#include <stdio.h>
int main()
{
printf("\nMain entry.\n");
return 0;
}
Makefile:
生成文件:
CC=gcc
CFLAGS=-I.
all: *.c
$(CC) -Os -Wall *.c -o helloworld
# $(STRIP) helloworld
clean:
rm -f a.out helloworld
rm -f *.o
Edit: And I have also added source "package/HelloWorld/Config.in"to 'package/Config.in' But when I mount my rootfs.ext2 partition I can't find my HelloWorld executable inside /usr/bin .., I am really new to this and don't have any prior knowledge, so could you please explain to me, what am I missing from this, because I'm sure I'm doing something wrong.
编辑:而且我还添加了源“package/HelloWorld/Config.in”到“package/Config.in”但是当我挂载我的 rootfs.ext2 分区时,我在 /usr/bin 中找不到我的 HelloWorld 可执行文件...,我对此真的很陌生,并且没有任何先验知识,所以请您向我解释一下,我错过了什么,因为我确定我做错了什么。
UPDATE:The program builds and install at the desired location but when I try to run it like so: ./helloworld, I get: bash: ./helloworld: No such file or directory, it has execution rights.. what is the matter with it? (I try to run it after I mount the rootfs.ext2 into a ubuntu directory, the target arch for buildroot is i368, so it should be ok, right?)
更新:程序在所需位置构建并安装,但是当我尝试像这样运行它时:./helloworld,我得到:bash:./helloworld:没有这样的文件或目录,它具有执行权限..这是怎么回事用它?(我把rootfs.ext2挂载到ubuntu目录后尝试运行,buildroot的目标arch是i368,所以应该没问题吧?)
After building and installing the HelloWorld program, and eventually running it, I'd like to add to init.d so it starts after booting, and replace the HelloWorld with a Qt Window that doesn't need a X server, like this thing here.
在构建和安装 HelloWorld 程序并最终运行它之后,我想添加到 init.d 以便它在启动后启动,并将 HelloWorld 替换为不需要 X 服务器的 Qt Window,就像这里的这个东西.
The main source of inspiration here.
灵感的主要来源在这里。
采纳答案by patrickdepinguin
In general, the sources for buildroot packages are taken from a (downloaded) tarball. What you are doing right now (placing the sources inside package/HelloWorld) is not the right way to proceed.
通常,buildroot 包的源来自(下载的)tarball。您现在正在做的事情(将源代码放在 package/HelloWorld 中)不是正确的方法。
Buildroot does have provisions for 'local' package sources, which you could use if you really need to. You'll need the HELLOWORLD_SITE_METHOD variable for that.
Buildroot 确实为“本地”包源提供了规定,如果您确实需要,可以使用它们。为此,您将需要 HELLOWORLD_SITE_METHOD 变量。
Please refer to http://buildroot.uclibc.org/downloads/manual/manual.html#adding-packagesfor more information.
有关更多信息,请参阅http://buildroot.uclibc.org/downloads/manual/manual.html#adding-packages。
Also, you don't need to define HELLOWORLD_DIR, HELLOWORLD_BINARY, HELLOWORLD_TARGET_BINARY.
此外,您不需要定义 HELLOWORLD_DIR、HELLOWORLD_BINARY、HELLOWORLD_TARGET_BINARY。
Update: regarding your additional question:
更新:关于您的其他问题:
UPDATE: The program builds and install at the desired location but when I try to run it like so: ./helloworld, I get: bash: ./helloworld: No such file or directory, it has execution rights.. what is the matter with it? (I try to run it after I mount the rootfs.ext2 into a ubuntu directory, the target arch for buildroot is i368, so it should be ok, right?)
更新:程序在所需位置构建并安装,但是当我尝试像这样运行它时:./helloworld,我得到:bash:./helloworld:没有这样的文件或目录,它具有执行权限..这是怎么回事用它?(我把rootfs.ext2挂载到ubuntu目录后尝试运行,buildroot的目标arch是i368,所以应该没问题吧?)
No, it does not work like that. You can't just mount rootfs.ext2 and expect to run programs from it. This is, among others, because the programs inside rootfs.ext2 are compiled against the libraries also inside rootfs.ext2, but if you run it like that it will use the libraries in /usr/lib. You either have to boot your system entirely with the rootfs.ext2, use qemu, or use a chroot environment. For chroot, you should use the 'tar' filesystem format, not ext2. See also here: http://buildroot.uclibc.org/downloads/manual/manual.html#_chroot
不,它不是那样工作的。您不能只是挂载 rootfs.ext2 并期望从中运行程序。这是因为 rootfs.ext2 中的程序也是针对 rootfs.ext2 中的库编译的,但是如果你这样运行它,它将使用 /usr/lib 中的库。您必须完全使用 rootfs.ext2 引导系统,使用 qemu,或者使用 chroot 环境。对于 chroot,您应该使用“tar”文件系统格式,而不是 ext2。另见此处:http: //buildroot.uclibc.org/downloads/manual/manual.html#_chroot