linker - 如何使用 gnatmake 或在 Ada 代码中将 Ada 库链接到 .adb 文件
问题描述
我正在使用 PLplot 运行测试代码,如下所示:
with PLplot_Auxiliary, PLplot_Standard;
use PLplot_Auxiliary, PLplot_Standard;
procedure xstandard00a is
x, y : Real_Vector(0 .. 100);
x_Min, y_Min : Long_Float := 0.0;
x_Max : Long_Float := 1.0;
y_Max : Long_Float := 100.0;
begin
-- Prepare data to be plotted.
for i in x'range loop
x(i) := Long_Float(i) / Long_Float(x'length - 1);
y(i) := y_Max * x(i)**2;
end loop;
-- Parse and process command line arguments.
Parse_Command_Line_Arguments(Parse_Full);
-- Initialize plplot.
Initialize_PLplot;
-- Create a labelled box to hold the plot.
Set_Environment(x_Min, x_Max, y_Min, y_Max,
Justification => Not_Justified,
Axis_Style => Linear_Box_Plus);
Write_Labels
(X_Label => "x",
Y_Label => "y=100 x#u2#d",
Title_Label => "Simple PLplot demo of a 2D line plot");
-- Plot the data that was prepared above.
Draw_Curve(x, y);
-- Close PLplot library.
End_PLplot;
end xstandard00a;
它不使用命令在 geany 中构建,gnatmake "%e"
也不通过命令编译gcc -Wall -c "%f"
。
它给了我错误:
xstandard00a.adb:20:05: file "plplot_auxiliary.ads" not found
xstandard00a.adb:21:05: file "plplot_standard.ads" not found
显然我必须链接到图书馆。PLplot的*.ali
文件位于/usr/lib64/ada/adalib/plplotada
.
如何与构建命令链接gnatmake
,或者如何添加额外的代码xstandard00a.adb
来查找那些 PLplot 库*.ali
?
更新:我运行带有示例(xstandard00a.adb)的 Make 文件,它编译成功。我打开 make 文件以查看它用于编译的标志。我准确地放置了这些标志并重新编译了另一个看起来像 xstanrd00a.adb 的示例,但它未能找到库。显然,除了 gnat make 使用的标志之外,还有其他东西。我错过了一些东西。Make文件编写如下,SHELL = /bin/bash GNAT_EXECUTABLE_BUILDER = /usr/bin/gnatmake
"-aI/usr/share/ada/adainclude/plplotada" "-aL/usr/lib64/ada/adalib /plplotada" EXEEXT =
PKG_CONFIG_ENV = PKG_CONFIG_PATH="/usr/lib64/pkgconfig::/usr/lib64/pkgconfig:/usr/share/pkgconfig"
install_tree_ada_RPATHCMD =
EXECUTABLES_list = \
xtraditional00a$(EXEEXT)
all: $(EXECUTABLES_list)
clean:
rm -f $(EXECUTABLES_list) *.ali *.o
# target_link_libraries( plplotada plplot)
# Due to command-line limitations of gnatmake cannot continue (by trailing \)
# anything after -cargs below.
.adb$(EXEEXT):
$(GNAT_EXECUTABLE_BUILDER) $< \
-cargs $(shell $(PKG_CONFIG_ENV) pkg-config --cflags plplot-ada plplot) -largs $(install_tree_ada_RPATHCMD) $(shell $(PKG_CONFIG_ENV) pkg- config --libs plplot-ada plplot)
.SUFFIXES: .adb $(EXEEXT)
我在编译/链接库中缺少什么?我使用 gnatmake -P 尝试了 gpr 方法,但仍然无法链接。到目前为止,唯一对我有用的方法是制作文件。但是,我想手动编译以弄清楚这个东西是如何工作的。我在 Geany IDE 的构建命令中写的是这样的:
gnatmake "%e" -aI/usr/share/ada/adainclude/plplotada -aL/usr/lib64/ada/adalib/plplotada
“%e”指的是 IDE 中的任何 adb 文件,在我的例子中是 simpleplot.adb,它基本上是 xstandard00a.adb
解决方案
在源代码旁边添加一个 .gpr 文件,例如,这个文件名为 xstandard.gpr:
with "/usr/share/gpr/plplotada.gpr";
project XStandard is
for Create_Missing_Dirs use "True";
for Source_Dirs use (".");
for Object_Dir use "obj";
package Builder is
for Executable ("xstandard00a.adb") use "xstandard";
end Builder;
end XStandard;
(已编辑;我已将“/usr/share/ada/adainclude/plplotada”放在此示例项目的源代码中,但最好使用包提供的 .gpr 文件)
然后执行gprbuild
. 我已经对此进行了测试,它适用于您给定的源文件。
我通过首先安装 plplotada 找到要包含的 gprfile,然后列出安装在我的系统上的所有文件:
sudo apt install libplplotada[Tab]
dpkg-query -L libplplotada2-dev
推荐阅读
- ruby-on-rails - 如何使用具有存储桶和文件名的 Aws::S3::Client 获取文件 URL?
- javascript - 如何在登录后重定向到页面,同时使用 express 将令牌作为处理程序发送到中间件
- regex - URL 中的正则表达式
- php - 将类添加到树枝模板中的某些字段项
- kotlin - 将 textview 更改为 println 输出
- oop - 在派生类型中声明变量与在 Fortran 子例程中声明变量有什么区别?
- excel - 如何将独特的产品颜色映射到 8 种基本颜色?
- javascript - 减少设置超时次数
- ios - 当我尝试将 Iphone 模拟器与树莓派连接时出现两个代码错误
- sql-server - 使用 SQL Server XML 数据类型,当使用另一个属性搜索以定位 xml 节点时,如何更新 value 属性?