Mix*_*xaz 5 linux gcc arm cross-compiling
我使用 sshfs 将目标设备(Beaglebone Black,ARM arch)的根目录安装到主机上的文件夹,并尝试使用--sysrootGCC 选项进行交叉编译。
但是有一个问题——一些包含头文件不仅位于目标设备上的 /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>
Run Code Online (Sandbox Code Playgroud)
因为sys/cdefs.h位于 /usr/include/arm-linux-gnueabihf 中,而编译器期望它在 /usr/include 中
我的问题是为什么我arm-linux-gnueabihf在 /usr/include 中有那个子文件夹?将部分包含文件(和 /usr/lib/arm-linux-gnueabihf 中的 .so 文件)放入该子文件夹的理由是什么?
在使用 --sysroot 选项进行交叉编译时,我应该如何解决这个问题 - 我是否需要使用 -I 和 -L 编译器选项指定子文件夹,或者有更好的解决方案?我虽然只有 --sysroot 应该足够了,但事实并非如此。那是“按设计”吗?
将文件夹添加到命令行后,我遇到了另一个问题:
[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
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?在构建 crosstool-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 )
Run Code Online (Sandbox Code Playgroud)
目标 GCC:
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)
Run Code Online (Sandbox Code Playgroud)
我在工具链配置中缺少什么?
添加:我发现以下文件负责将库放置到目标上的该子文件夹:
debian@beaglebone:~$ cat /etc/ld.so.conf.d/arm-linux-gnueabihf.conf
# Multiarch support
/lib/arm-linux-gnueabihf
/usr/lib/arm-linux-gnueabihf
Run Code Online (Sandbox Code Playgroud)
现在我试图了解将这些文件夹附加到交叉编译器工具链的正确方法是什么。
另外,我想为包含头文件设置了类似的内容,只是有趣的目标上的 GCC 设置在哪里?
添加:针对 RPi 交叉编译讨论的类似问题:https : //github.com/raspberrypi/tools/issues/42
我将发布调查结果作为答案,但如果它解决了问题,我会接受 - 我还没有找到解决方案)
目标的 GCC 似乎是使用 --enable-multiarch 配置的,并且它arm-linux-gnueabihf为该目标名称添加了子文件夹。
关于该主题的好读物是https://wiki.debian.org/Multiarch/LibraryPathOverview
所以我的问题可能是交叉编译 GCC 中的目标名称与目标 GCC 上的目标名称不同(arm-cortexa9_neon-linux-gnueabihfvs arm-linux-gnueabihf)。我会检查是否可以在crosstool-NG选项中更改它,看看是否可以解决问题。
添加:不幸的是,我无法配置crosstool-ng工具链以使用目标 sysroot。这里报告了类似的问题:http://answers.opencv.org/question/180037/cmake-cross-compiler-problem-with-pkg_check_modules-for-some-packages/
我最终决定使用dockcross/linux-armv6安装了为 RPi 定制的 linaro 工具链的镜像,至少它可以从 box 编译“hello world”。尽管该工具链似乎也源自 crosstool-ng,但它是从 RPi 工具存储库以二进制形式下载的,并且其配置与dockcross/linux-armv7.
现在我尝试按照本指南交叉编译 OpenCV:http://courses.engr.uky.edu/ideawiki/doku.php ?id=resources:sop:cross_compiling_opencv_for_raspberry_pi 并在指定 pkg-config、OpenCV cmake 脚本的路径之后开始在目标的 sysroot 中查看已安装的库。