如何使用 NetBSD 构建交叉编译 NetBSD 工具链

How to build a cross compile NetBSD toolchain using NetBSD

我有一个使用 qemu 创建的 NetBSD VM,我正在尝试使用交叉编译工具链编译一个简单的 Hello World.c 程序,该工具链是我使用 build.sh 脚本构建的NetBSD 源代码。但是,我无法编译程序。

我使用以下命令构建了工具链,

./build.sh -m evbarm tools

./build.sh -m evbarm -U distribution

上述命令的输出结果为,

===> Tools built to /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386
===> build.sh ended:   Sat Nov 28 12:52:34 CST 2015
===> Summary of results:
         build.sh command: ./build.sh -m evbarm tools
         build.sh started: Sat Nov 28 12:48:47 CST 2015
         NetBSD version:   4.0
         MACHINE:          evbarm
         MACHINE_ARCH:     arm
         Build platform:   NetBSD 4.0.1 i386
         HOST_SH:          /bin/sh
         No nonexistent/bin/nbmake, needs building.
         Bootstrapping nbmake
         TOOLDIR path:     /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386
         DESTDIR path:     /opt/cross/evbarm/usr/src/destdir.evbarm
         RELEASEDIR path:  /opt/cross/evbarm/usr/src/releasedir
         Created /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/nbmake
         makewrapper:      /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/nbmake-evbarm
         Updated /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/nbmake-evbarm
         Tools built to /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386
         build.sh ended:   Sat Nov 28 12:52:34 CST 2015
===> .


make distribution started at:  Sat Nov 28 14:31:23 CST 2015
make distribution finished at: Sat Nov 28 15:04:34 CST 2015
===> Successful make distribution
===> build.sh ended:   Sat Nov 28 15:04:34 CST 2015
===> Summary of results:
         build.sh command: ./build.sh -m evbarm -U distribution
         build.sh started: Sat Nov 28 14:31:20 CST 2015
         NetBSD version:   4.0
         MACHINE:          evbarm
         MACHINE_ARCH:     arm
         Build platform:   NetBSD 4.0.1 i386
         HOST_SH:          /bin/sh
         No nonexistent/bin/nbmake, needs building.
         Bootstrapping nbmake
         TOOLDIR path:     /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386
         DESTDIR path:     /opt/cross/evbarm/usr/src/destdir.evbarm
         RELEASEDIR path:  /opt/cross/evbarm/usr/src/releasedir
         Created /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/nbmake
         makewrapper:      /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/nbmake-evbarm
         Updated /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/nbmake-evbarm
         Successful make distribution
         build.sh ended:   Sat Nov 28 15:04:34 CST 2015
===> .

但是,当我尝试使用 nbmake-evbarm 包装器编译 helloARM.c 时,我得到以下输出,

$ nbmake-evbarm ./helloARM
/opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/arm--netbsdelf-gcc -O2   -Werror    -nostdinc -isystem /opt/cross/evbarm/usr/src/destdir.evbarm/usr/include    -o ./helloARM ./helloARM.c 
/opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/lib/gcc/arm--netbsdelf/4.1.2/../../../../arm--netbsdelf/bin/ld: crt0.o: No such file: No such file or directory
collect2: ld returned 1 exit status

*** Failed target:  ./helloARM
*** Failed command: /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/arm--netbsdelf-gcc -O2 -Werror -nostdinc -isystem /opt/cross/evbarm/usr/src/destdir.evbarm/usr/include -o ./helloARM ./helloARM.c 
*** Error code 1

Stop.
nbmake: stopped in /home/capin/apps

不要将 ./ 路径前缀放在目标名称上。

即只是 运行:

nbmake-evbarm helloARM

我当然假设您在同一目录中有一个 Makefile,看起来有点像这样,至少:

PROG = helloARM

.include <bsd.prog.mk>

你必须有这样一个使用标准 NetBSD 宏的本地 Makefile 因为当没有 makefile 时(或者当 makefile 没有使用正确的 NetBSD 宏时,即 <bsd.prog.mk>)默认sys.mk 使用了宏,它们不包括访问目标系统的头文件和库等所需的所有 ${DESTDIR} 魔法。