我用sshfs将目标设备的根(Beaglebone Black,ARM arch)安装到主机上的一个文件夹中,并尝试使用
--sysroot
但有一个问题-有些include头文件不仅位于/usr/include文件夹中,还位于其子文件夹中
arm-linux-gnueabihf
. 同样还有/usr/lib/arm linux gnueabihf文件夹。
“Hello world”示例编译失败
[gmixaz:/work] $ $CC --sysroot=/work/sysroot h.c
In file included from /work/sysroot/usr/include/stdio.h:27:0,
from h.c:1:
/work/sysroot/usr/include/features.h:364:25: fatal error: sys/cdefs.h: No such file or directory
# include <sys/cdefs.h>
sys/cdefs.h
我的问题是为什么我有那个子文件夹
在/使用/包含?把include文件的一部分(以及/usr/lib/arm-linux-gnueabihf中的.so文件)放入该子文件夹的原理是什么?
在将文件夹添加到命令行后,我遇到了另一个问题:
[gmixaz:/work] 1 $ $CC --sysroot /work/sysroot3 -I /work/sysroot3/usr/include/arm-linux-gnueabihf -L /work/sysroot3/usr/lib/arm-linux-gnueabihf h.c
/usr/xcc/arm-cortexa9_neon-linux-gnueabihf/lib/gcc/arm-cortexa9_neon-linux-gnueabihf/6.3.1/../../../../arm-cortexa9_neon-linux-gnueabihf/bin/ld.bfd: cannot find crt1.o: No such file or directory
/usr/xcc/arm-cortexa9_neon-linux-gnueabihf/lib/gcc/arm-cortexa9_neon-linux-gnueabihf/6.3.1/../../../../arm-cortexa9_neon-linux-gnueabihf/bin/ld.bfd: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status
发生什么事?当建立交叉工具NG时,我试图匹配目标拱门信息。在主机上交叉编译GCC:
[gmixaz:/work] 1 $ $CC -v
Using built-in specs.
COLLECT_GCC=/usr/xcc/arm-cortexa9_neon-linux-gnueabihf/bin/arm-cortexa9_neon-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/usr/xcc/arm-cortexa9_neon-linux-gnueabihf/libexec/gcc/arm-cortexa9_neon-linux-gnueabihf/6.3.1/lto-wrapper
Target: arm-cortexa9_neon-linux-gnueabihf
Configured with: /dockcross/crosstool/toolchain/.build/src/gcc-linaro-6.3-2017.02/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=arm-cortexa9_neon-linux-gnueabihf --prefix=/usr/xcc/arm-cortexa9_neon-linux-gnueabihf --with-sysroot=/usr/xcc/arm-cortexa9_neon-linux-gnueabihf/arm-cortexa9_neon-linux-gnueabihf/sysroot --enable-languages=c,c++ --with-cpu=cortex-a8 --with-fpu=neon --with-float=hard --with-pkgversion='crosstool-NG ' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --disable-libmpx --with-gmp=/dockcross/crosstool/toolchain/.build/arm-cortexa9_neon-linux-gnueabihf/buildtools --with-mpfr=/dockcross/crosstool/toolchain/.build/arm-cortexa9_neon-linux-gnueabihf/buildtools --with-mpc=/dockcross/crosstool/toolchain/.build/arm-cortexa9_neon-linux-gnueabihf/buildtools --with-isl=/dockcross/crosstool/toolchain/.build/arm-cortexa9_neon-linux-gnueabihf/buildtools --enable-lto --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-plugin --enable-gold --with-libintl-prefix=/dockcross/crosstool/toolchain/.build/arm-cortexa9_neon-linux-gnueabihf/buildtools --disable-multilib --with-local-prefix=/usr/xcc/arm-cortexa9_neon-linux-gnueabihf/arm-cortexa9_neon-linux-gnueabihf/sysroot --enable-long-long
Thread model: posix
gcc version 6.3.1 20170109 (crosstool-NG )
debian@beaglebone:~$ cc -v
Using built-in specs.
COLLECT_GCC=cc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Debian 6.3.0-18+deb9u1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-armhf/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-armhf --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-armhf --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)
我在工具链配置中缺少什么?
补充:
我发现以下文件负责将库放置到目标上的该子文件夹中:
debian@beaglebone:~$ cat /etc/ld.so.conf.d/arm-linux-gnueabihf.conf
# Multiarch support
/lib/arm-linux-gnueabihf
/usr/lib/arm-linux-gnueabihf
现在我正在尝试理解将文件夹附加到交叉编译器工具链的正确方法是什么。
另外,我想对于include头文件也设置了类似的设置,有趣的是GCC在target上的设置在哪里?
为RPi交叉编译讨论的类似问题:
https://github.com/raspberrypi/tools/issues/42