【问题标题】:cross compiling with autoconf使用 autoconf 进行交叉编译
【发布时间】:2017-05-03 07:24:10
【问题描述】:

我试图用 autoconf 进行交叉编译。 我曾尝试过这些帮助:

  1. https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Hosts-and-Cross_002dCompilation.html

  2. https://www.gnu.org/software/autoconf/manual/autoconf-2.65/html_node/Specifying-Target-Triplets.html

  3. https://github.com/jedisct1/libsodium/issues/274
  4. Cross Compiling For ARM With Autoconf

并且做到了-

./configure --build=x86_64-linux-gnu --host=/opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf --target=/opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf --disable-shared --disable-documentation

但是在 autoconf 工具检查 gcc 和其他编译所需的东西之后,它没有找到这些。尽管它们已经存在于目录中。

所以日志是:

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for /opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-strip... no
checking for strip... strip
configure: WARNING: using cross tools not prefixed with host triplet
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for /opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for /opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ar... no
checking for /opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-lib... no
checking for /opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-link... no
checking for ar... ar
checking the archiver (ar) interface... ar
checking build system type... x86_64-pc-linux-gnu
checking host system type... Invalid configuration `/opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf': machine `/opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin/arm' not recognized
configure: error: /bin/bash ./config.sub /opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf failed

这是所有arm工具链bin的目录

host@ubuntu:/opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin$ ls
arm-linux-gnueabihf-addr2line  arm-linux-gnueabihf-gcc         arm-linux-gnueabihf-gfortran  arm-linux-gnueabihf-readelf
arm-linux-gnueabihf-ar         arm-linux-gnueabihf-gcc-5.4.1   arm-linux-gnueabihf-gprof     arm-linux-gnueabihf-size
arm-linux-gnueabihf-as         arm-linux-gnueabihf-gcc-ar      arm-linux-gnueabihf-ld        arm-linux-gnueabihf-strings
arm-linux-gnueabihf-c++        arm-linux-gnueabihf-gcc-nm      arm-linux-gnueabihf-ld.bfd    arm-linux-gnueabihf-strip
arm-linux-gnueabihf-c++filt    arm-linux-gnueabihf-gcc-ranlib  arm-linux-gnueabihf-nm        gdbserver
arm-linux-gnueabihf-cpp        arm-linux-gnueabihf-gcov        arm-linux-gnueabihf-objcopy   runtest
arm-linux-gnueabihf-elfedit    arm-linux-gnueabihf-gcov-tool   arm-linux-gnueabihf-objdump
arm-linux-gnueabihf-g++        arm-linux-gnueabihf-gdb         arm-linux-gnueabihf-ranlib

有什么建议吗?

编辑 我尝试了 Chrono 建议的解决方案。它能够找到手臂工具链。但是又出现了一个问题:

添加符号时出错:文件格式无法识别

libtool: link: arm-linux-gnueabihf-gcc -shared  -fPIC -DPIC  src/.libs/libcoap_1_la-address.o src/.libs/libcoap_1_la-async.o src/.libs/libcoap_1_la-block.o src/.libs/libcoap_1_la-coap_dtls.o src/.libs/libcoap_1_la-coap_event.o src/.libs/libcoap_1_la-coap_keystore.o src/.libs/libcoap_1_la-coap_time.o src/.libs/libcoap_1_la-debug.o src/.libs/libcoap_1_la-encode.o src/.libs/libcoap_1_la-hashkey.o src/.libs/libcoap_1_la-mem.o src/.libs/libcoap_1_la-net.o src/.libs/libcoap_1_la-option.o src/.libs/libcoap_1_la-pdu.o src/.libs/libcoap_1_la-resource.o src/.libs/libcoap_1_la-str.o src/.libs/libcoap_1_la-subscribe.o src/.libs/libcoap_1_la-uri.o src/platform/posix/.libs/libcoap_1_la-coap_io.o src/platform/posix/.libs/libcoap_1_la-prng.o src/platform/posix/.libs/libcoap_1_la-run.o   -L./ext/tinydtls -ltinydtls  -g -O2 -Wl,--version-script=./libcoap-1.map   -Wl,-soname -Wl,libcoap-1.so.0 -o .libs/libcoap-1.so.0.0.0

对于这行编译,错误是:

./ext/tinydtls/libtinydtls.a: error adding symbols: File format not recognized

编辑 2:

问题出在库中,它没有正确地将交叉编译器参数传递给 autoconf,因此出现了问题。

【问题讨论】:

标签: c cross-compiling autoconf


【解决方案1】:

确保包含您的工具链二进制文件的目录位于您的$PATH

export OLDPATH=$PATH
export PATH=$OLDPATH:/opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin

您应该只需要这样做一次,除非您注销或以其他方式退出该终端会话。

完成后,您可以正确配置:

./configure \
    --build=x86_64-linux-gnu \
    --host=arm-linux-gnueabihf \
    --target=arm-linux-gnueabihf \
    --disable-shared \
    --disable-documentation

【讨论】:

  • 它能够找到交叉编译工具链,但出现另一个错误:添加符号时出错:文件格式无法识别。请查看编辑
  • 我正在编译的库里面有另一个库。通过父库的autoconf,子库的autoconf也在做。但在这种情况下,它不会从 autocong 中获取 arm crosstool。它是用 cc 编译的,而不是 arm gcc。
  • @ninja.stop 这将在另一个问题中更好地探讨,因为需要额外的细节(也许这是您正在编译的库的一个已知问题?),但 this mailing list thread 可能是一个好的开始。
  • 是的。这确实是那个图书馆的问题。邮寄给他们。根据作者的说法,它已被修补。让我们来看看。顺便说一句,感谢您的帮助:)
猜你喜欢
  • 2013-02-20
  • 1970-01-01
  • 2020-07-05
  • 2013-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多