我正在尝试构建一个简单的“hello_there”Ada 应用程序以在 Raspberry Pi 2/Raspbian 机器上运行,但遇到了链接问题。
到目前为止,我已经完成了以下工作并遇到了以下问题:
在主机 (Ubuntu 16.04) 上下载了用于交叉编译 (linux-on-linux) 的“Raspberry Pi 2 Linux”GNAT GPL Ada 工具链
在主机上成功运行“doinstall”。
创建了一个简单的“hello_there.adb”文件,它只向控制台打印一条消息。
运行 {INSTALL_ROOT}/gnat-gpl-2016-raspberrypi-linux-linux-bin/bin/arm-linux-gnueabihf-gnatmake -v hello_there.adb 来构建这个小的应用程序。
提示crt1.o | crti.o |找不到 crtn.o 文件,因为我无法在主机上使用 /usr/lib/x86_64-linux-gnu/ 下的文件(正如我假设的那样,这些只能用于 x86 目标)我能找到的唯一解决方案是将这些文件从位于 /usr/lib/arm-linux-gnueabihf 下的目标机器复制到 gnatmake命令目录这阻止了链接器提示这些。
再次运行 {INSTALL_ROOT}/gnat-gpl-2016-raspberrypi-linux-linux-bin/bin/arm-linux-gnueabihf-gnatmake -v hello_there.adb 但现在链接器提示以下错误:
{INSTALL_ROOT}/gnat-gpl-2016-raspberrypi-linux-linux-bin/bin/../libexec/gcc/arm-linux-gnueabihf/4.9.4/ld:找不到-lc
看起来编译和绑定(bind)完全正常,但链接失败。完整输出如下:
GNATMAKE GPL 2016 (20160515-49) Copyright (C) 1992-2016, Free Software Foundation, Inc. "hello_there.ali" being checked ... -> "hello_there.ali" missing. arm-linux-gnueabihf-gcc -c hello_there.adb End of compilation arm-linux-gnueabihf-gnatbind -x hello_there.ali arm-linux-gnueabihf-gnatlink hello_there.ali /home/savvas/opt/GNAT/gnat-gpl-2016-raspberrypi-linux-linux-bin/bin/../libexec/gcc/arm-linux-gnueabihf/4.9.4/ld: cannot find -lc collect2: error: ld returned 1 exit status arm-linux-gnueabihf-gnatlink: error when calling /home/savvas/opt/GNAT/gnat-gpl-2016-raspberrypi-linux-linux-bin/bin/arm-linux-gnueabihf-gcc arm-linux-gnueabihf-gnatmake: *** link failed.
链接器是在寻找库路径中某处的 clib(或其他文件名?)文件,还是正在发生其他事情?我是 gcc 编译/链接的新手,正在尝试理解这一点。
任何指点,非常感谢。
谢谢
最佳答案
在使用此特定版本的 GNAT(交叉)编译器之前,您需要先将一些其他文件从 RPi 2 复制到主机。 README 中解释了确切的步骤特定 GNAT 版本附带的文件。为方便起见,我将相关部分复制到此答案的末尾。
也就是说,也可以考虑先使用较新版本的 GNAT(Community Edition 或 an FSF version)在 Ubuntu 上开发您的程序,然后将源代码复制到 Raspberry Pi,并在 Pi 本身上重新编译。 Debian 存储库中提供的 GNAT FSF 编译器(和相关工具)也可用于 Raspberry Pi OS:
$ sudo apt install gnat gprbuild
最后,您还可以考虑使用 Alire (至少在主机上)。 Alire 尚无对 Raspberry Pi 的官方支持,但已提供实验版本 here .
自述文件摘录:
Raspberrypi 2 (hosted on Linux)
The GNAT GPL compiler for raspberrypi is a cross compiler, hosted on linux-x86 (or linux-x86_64). You need to copy from the boards some library files. The following script achieves that. It should be executed from
<GNAT GPL>/arm-linux-gnueabihf
(theRPI
variable is login@target):#!/bin/sh RPI=pi@myboard mkdir sysroot sysroot/lib sysroot/lib/arm-linux-gnueabihf cd sysroot/lib rsync -a $RPI:/lib/arm-linux-gnueabihf/{ld-*,lib?.*,lib?-*,libpthread*,librt*} arm-linux-gnueabihf ln -s arm-linux-gnueabihf/lib?.* . cd ../.. mkdir sysroot/usr sysroot/usr/lib sysroot/usr/lib/arm-linux-gnueabihf cd sysroot/usr/lib/arm-linux-gnueabihf rsync -a $RPI:/usr/lib/arm-linux-gnueabihf {crt*,libc.*,libc_no*,libpthread*} . ln -s ../../../lib/arm-linux-gnueabihf/libm.so.* libm.so ln -s ../../../lib/arm-linux-gnueabihf/librt.so.* librt.so cd .. ln -s arm-linux-gnueabihf/* .
Before running a GNAT GPL tool, set
ENV_PREFIX
variable like this:export ENV_PREFIX=<GNAT GPL>/arm-linux-gnueabihf/sysroot
关于cross-compiling - GNAT GPL Ada 在为 Raspberry pi 交叉编译时失败将链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71575408/