【发布时间】:2021-02-12 15:22:21
【问题描述】:
我正在使用 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;
它不使用命令gnatmake "%e" 在geany 中构建,也不通过命令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?
更新:
我运行随示例提供的 Make 文件 (xstandard00a.adb) 并成功编译。我打开 make 文件以查看它用于编译的标志。我准确地放置了这些标志并重新编译了另一个看起来像 xstanrd00a.adb 的示例,但它未能找到库。显然,除了 gnat make 使用的标志之外,还有其他东西。我错过了一些东西。 Make文件的写法如下,
外壳 = /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 的 build 命令中写的是这样的:
gnatmake "%e" -aI/usr/share/ada/adainclude/plplotada -aL/usr/lib64/ada/adalib/plplotada
"%e" 指的是 IDE 中的任何 adb 文件,在我的例子中 simpleplot.adb 基本上是 xstandard00a.adb
【问题讨论】:
-
如果您的库的 .ads、.ali 和 .o 文件都在目录 lib_dir(绝对或相对路径)中,那么只需将
-Ilib_dir添加到 gnatmake 即可。有些人喜欢通过将各种文件放在不同的目录中来使事情变得更复杂。如果你或 PL Plot 安装程序已经这样做了,那么让它与 gnatmake 一起工作会更复杂,当然。
标签: linker shared-libraries ada