简体   繁体   English

从设备与sysroot交叉编译

[英]cross compiling with sysroot from device

I mounted target device's (Beaglebone Black, ARM arch) root with sshfs, to a folder on host, and trying to cross compile using --sysroot option of GCC. 我将带有sshfs的目标设备(Beaglebone Black,ARM arch)的根目录安装到主机上的文件夹中,并尝试使用GCC的--sysroot选项进行交叉编译。

But there's a problem - some include header files are located on target device not just at /usr/include folder, but in its subfolder arm-linux-gnueabihf . 但是存在一个问题-有些包含头文件不仅位于目标设备上的/ usr / include文件夹中,而且位于其子文件夹arm-linux-gnueabihf The same there's /usr/lib/arm-linux-gnueabihf folder too. 同样也有/ usr / lib / arm-linux-gnueabihf文件夹。

"Hello world" sample fails to compile “ 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>

because sys/cdefs.h is located in /usr/include/arm-linux-gnueabihf, while compiler expects it in /usr/include 因为sys/cdefs.h位于/ usr / include / arm-linux-gnueabihf中,而编译器希望它位于/ usr / include中

My question is why do I have that subfolder arm-linux-gnueabihf in /usr/include? 我的问题是为什么我在/ usr / include中有该子文件夹arm-linux-gnueabihf What was the rationale to put part of include files (and .so files in /usr/lib/arm-linux-gnueabihf) to that subfolder? 将包含文件(和/ so / lib / arm-linux-gnueabihf中的.so文件)的一部分放到该子文件夹的理由是什么?

And how shall I address this issue when cross compiling with --sysroot option - do I need to specify the subfolder with -I and -L compiler options, or there's some better solution? 当使用--sysroot选项交叉编译时,如何解决此问题-我需要使用-I和-L编译器选项指定子文件夹,还是有一些更好的解决方案? I though only --sysroot should be enough but it isn't. 我虽然--sysroot应该足够了,但事实并非如此。 Is that 'by design'? 那是“设计使然”吗?

After adding the folders to command line I got another problem: 将文件夹添加到命令行后,我遇到了另一个问题:

[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

What's going on? 这是怎么回事? When building crosstool-NG I tried to match target arch info. 在构建crosstool-NG时,我尝试匹配目标拱形信息。 Cross-compiling GCC on host: 在主机上交叉编译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 ) 

GCC on target: 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) 

What I'm missing in the toolchain configuration? 我在工具链配置中缺少什么?

ADDED: I have found that following file is responsible for libraries being placed to that subfolder on target: 添加:我发现以下文件负责将库放置到目标上的该子文件夹:

debian@beaglebone:~$ cat /etc/ld.so.conf.d/arm-linux-gnueabihf.conf
# Multiarch support
/lib/arm-linux-gnueabihf
/usr/lib/arm-linux-gnueabihf

Now I'm trying to understand what is correct way to attach that folders to cross compiler toolchain. 现在,我试图了解将文件夹附加到跨编译器工具链的正确方法是什么。

Also, I guess that something similar is set for include header files, just interesting where's that setting for GCC on target? 另外,我猜想为头文件头设置了类似的东西,只是有趣的是,目标上的GCC设置在哪里?

ADDED: Similar issue discussed for RPi cross compilation: https://github.com/raspberrypi/tools/issues/42 添加:针对RPi交叉编译讨论的类似问题: https : //github.com/raspberrypi/tools/issues/42

I'm posting results of my investigation as an answer, but will accept if it solves the problem - I haven't got a solution yet ) 我将调查的结果作为答案发布,但可以解决是否可以接受-我还没有解决方案)

It appears that the target's GCC was configured with --enable-multiarch, and it adds arm-linux-gnueabihf subfolder for that target name. 似乎目标的GCC已配置--enable-multiarch,并且为该目标名称添加了arm-linux-gnueabihf子文件夹。

Good reading about the subject is https://wiki.debian.org/Multiarch/LibraryPathOverview 关于这个主题的好阅读是https://wiki.debian.org/Multiarch/LibraryPathOverview

So probably my problem is that target name in the cross compiling GCC differs from that on the target's GCC ( arm-cortexa9_neon-linux-gnueabihf vs arm-linux-gnueabihf ). 因此,可能是我的问题是交叉编译GCC中的目标名称与目标GCC上的目标名称不同( arm-cortexa9_neon-linux-gnueabihfarm-linux-gnueabihf )。 I'll check if I can change it in crosstool-NG options, and see if it fixes the issue. 我将检查是否可以在crosstool-NG选项中对其进行更改,然后查看它是否可以解决该问题。

ADDED: Unfortunately I was not able to configure crosstool-ng toolchain to use target sysroot. 添加:不幸的是,我无法配置crosstool-ng工具链以使用目标sysroot。 Similar issue was reported here: http://answers.opencv.org/question/180037/cmake-cross-compiler-problem-with-pkg_check_modules-for-some-packages/ 此处报告了类似的问题: http : //answers.opencv.org/question/180037/cmake-cross-compiler-problem-with-pkg_check_modules-for-some-packages/

I have finally decided to use dockcross/linux-armv6 image which installs linaro toolchain customized for RPi, at least it compiles "hello world" from box. 我最终决定使用dockcross/linux-armv6映像,该映像安装了为RPi定制的linaro工具链,至少它可以从盒子中编译“ hello world”。 Though the toolchain seems to be derived also from crosstool-ng, it is downloaded as binary from RPi tools repo, and its configuration significantly differs from one for dockcross/linux-armv7 . 尽管该工具链似乎也是从crosstool-ng派生的,但它是从RPi工具仓库以二进制形式下载的,其配置与dockcross/linux-armv7配置明显不同。

Now I'm trying to cross compile OpenCV per this guide: http://courses.engr.uky.edu/ideawiki/doku.php?id=resources:sop:cross_compiling_opencv_for_raspberry_pi and after specifying paths for pkg-config, OpenCV cmake script started to see installed libraries in target's sysroot. 现在,我尝试按照此指南交叉编译OpenCV: http ://courses.engr.uky.edu/ideawiki/doku.php?id=resources:sop: cross_compiling_opencv_for_raspberry_pi,并在为pkg-config指定路径后,使用OpenCV cmake脚本开始在目标的sysroot中查看已安装的库。

Actually, I don't want to dig into your way because I think it is not a common way to cross compiling. 实际上,我不想深入探讨您的方法,因为我认为这不是交叉编译的常见方法。 The way you are cross-compiling is not suggested. 不建议使用交叉编译的方式。 There are two common ways to cross-compile an app. 有两种常见的方法可以交叉编译应用程序。

First, creating a virtual environment just like your embedded board with some virtualization apps like Qemu . 首先,使用Qemu类的虚拟化应用程序来创建虚拟环境,就像嵌入式板一样。 You can find a very good tutorial here . 您可以在这里找到一个很好的教程。 Then you can bring your app there and compile it natively. 然后,您可以将您的应用程序带到那里并进行本地编译。 A drawback for this solution is you are creating a whole filesystem and you should bring all of your app dependencies (which may become confusing) into your main filesystem. 该解决方案的缺点是您要创建一个完整的文件系统,并且应将所有应用程序依赖项(可能会造成混淆)引入主文件系统。

Second, you can use Linaro toolchains to cross-compile your app. 其次,您可以使用Linaro toolchains来交叉编译您的应用程序。 Here is another tutorial and I think you can find more about it. 这是另一个教程 ,我想您可以找到更多关于它的信息。

In my opinion, I prefer using Qemu when I need to build the app natively which have a lot of dependencies. 我认为,当我需要原生构建具有很多依赖关系的应用程序时,我更喜欢使用Qemu。 On the other hand, cross-compiling apps that don't natively support it can become very confusing. 另一方面,本机不支持它的交叉编译应用程序可能会变得非常混乱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM