【发布时间】:2020-02-04 21:52:23
【问题描述】:
我需要使用一个外部构建的 C 库对我的 Ada 程序使用三角函数服务进行一些计算。我使用 stm32 bb 运行时 (SFP) 做得很好,但是当尝试使用默认的 Ada 运行时在本机环境中做同样的事情时,我最终遇到了链接问题。希望我能在这里找到一些帮助。
我尝试了几种项目文件 (gpr) 解决方案的配置,但总是以同样的链接错误结束:
Memory region Used Size Region Size %age Used/opt/gnat/gnat_native/bin/../libexec/gcc/x86_64-pc-linux-gnu/7.3.1/ld: /home/pulsar/repos/pulsar-software/something/lib_c/libC.a(something.o): in function `compute':
(.text+0xa5): undefined reference to `sin'
collect2: error: ld returned 1 exit status
这是我到目前为止所得到的。
C 库构建顺序如下(由库提供者确认):
$ gcc -c something.c -o something.o
$ ar -r libsomethingLib.a something.o
C 库 gpr 文件something_lib_c.gpr:
library project Something_Lib_C is
for Languages use ("C");
for Externally_Built use "true";
for Source_Dirs use ("src_c");
for Library_Dir use "lib_c";
for Library_Name use "somethingLib";
for Library_Kind use "static";
end Geocaging_Lib_C;
在 lib_c 目录中,我有实际的库libsomethingLib.a
在src_c 目录中,我有头API 来使用C 库(something.h):
#ifndef _GEOCAGING_H
#define _GEOCAGING_H
typedef struct something_s something_t;
extern void compute(something_t* const self);
#endif // _GEOCAGING_H
那么这里是包装C库something_lib.gpr的Ada工程文件:
with "something_lib_c.gpr";
project Something_Lib extends "../settings.gpr" is
for Languages use ("Ada");
for Source_Dirs use ("./src_ada");
for Object_Dir use "obj" & "/" & Target & "/" & Build;
end Geocaging_Lib;
在目录 src_ada 中,我有 Ada API 包装器 (something_api.ads):
with Interfaces; use Interfaces;
with Interfaces.C; use Interfaces.C;
package Something_API is
type T_Something is null record;
procedure Compute (Something : access T_Something);
with Import => True,
Convention => C,
External_Name => "compute";
end Something_API;
最后,我通过使用 Ada API 包装器从我的 Ada 程序中调用计算服务。
再一次,当为 arm-eabi 目标构建/链接整个事物时,使用 stm32-full 或 stm32-sfp Ada 运行时,一切运行良好并且库的行为得到验证。
关键是我想在本地环境中做这件事以便在其上运行 CI 测试,但我找不到通过链接阶段的方法。
最后一件事,在Settings.gpr 通用项目文件中包含一些常见的 Ada 构建/绑定/构建开关,我可以在必要时提供这些开关。但我看不出这如何在 arm 中工作,而不是在具有相同选项的 native 中工作。这必须链接到默认的 Ada 运行时事物...
有什么想法吗?
【问题讨论】:
-
与数学库的链接:
gcc ... -lm -
@JL2210,感谢您的回答。我自己无法生成 C 库,它是第三方库。而且我不希望制作人嵌入他们的数学库,我想使用我的(即 ada 运行时数学库)。这就是为什么实际上会生成没有部分链接的存档的原因。
标签: c linker cross-compiling ada