代码之家  ›  专栏  ›  技术社区  ›  Mixaz

从设备使用sysroot交叉编译

  •  2
  • Mixaz  · 技术社区  · 7 年前

    我用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

    2 回复  |  直到 7 年前
        1
  •  0
  •   Mixaz    7 年前

    目标的GCC似乎配置了--enable multiarch,并添加了 arm-linux-gnueabihf 该目标名称的子文件夹。

    关于这个主题的好读物是 https://wiki.debian.org/Multiarch/LibraryPathOverview

    arm-cortexa9_neon-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 tools repo下载的二进制文件,其配置与for的配置有很大不同 dockcross/linux-armv7

    现在,我正尝试按照以下指南交叉编译OpenCV: http://courses.engr.uky.edu/ideawiki/doku.php?id=resources:sop:cross_compiling_opencv_for_raspberry_pi

        2
  •  0
  •   Masoud Rahimi Chris    7 年前

    实际上,我不想深入研究你的方法,因为我认为交叉编译不是一种常见的方法。 不建议使用交叉编译的方式。交叉编译应用程序有两种常见方法。

    首先,创建一个虚拟环境,就像你的嵌入式电路板一样,使用一些虚拟化应用程序,比如 Qemu here . 然后你可以把你的应用程序带到那里,并在本地编译它。此解决方案的一个缺点是您正在创建一个完整的文件系统,您应该将所有应用程序依赖项(这可能会变得混乱)引入主文件系统。

    Linaro toolchains tutorial 我想你可以找到更多的信息。