2
votes

I am running a test code using PLplot as follows:

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;

It does not build in geany using the command gnatmake "%e" and does not compile by command gcc -Wall -c "%f".

It gives me the error:

 xstandard00a.adb:20:05: file "plplot_auxiliary.ads" not found
 xstandard00a.adb:21:05: file "plplot_standard.ads" not found

Obviously I have to link to libraries. The *.ali files of PLplot are located at /usr/lib64/ada/adalib/plplotada.

How do I link with build command gnatmake, or how do I add extra code in xstandard00a.adb to find those PLplot libraries *.ali?

Update: I run Make file provided with examples (xstandard00a.adb) and it compiled successfully. I opened make file to see flags it uses to compile. I put those flags exactly and recompile another example that looks like xstanrd00a.adb and it failed to find libraries. Obviously there is something else besides flags used by gnat make. I am missing something. The Make file is written as follows, 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)

What I am missing in compilation/linking libraries? I tried the gpr method using gnatmake -P and still failed to link. So far the only method that works for me is Make file. However, I want to compile manually to figure out how this thing works. What I wrote in build command in Geany IDE was this:

gnatmake "%e" -aI/usr/share/ada/adainclude/plplotada -aL/usr/lib64/ada/adalib/plplotada

"%e" refers to any adb file in IDE and in my case simpleplot.adb which is basically xstandard00a.adb

2
If your library's .ads, .ali, and .o files are all in directory lib_dir (absolute or relative path), then it's a simple matter of adding -Ilib_dir to gnatmake. Some people like to make things more complicated for themselves by putting the various kinds of files in different directories. If you or the PL Plot installer have done that, then getting it to work with gnatmake will be more complicated, of course.Jeffrey R. Carter

2 Answers

3
votes

Add a .gpr file next to your sources, for instance, this one is called 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;

(edited; I had put "/usr/share/ada/adainclude/plplotada" in the Sources of this example project, but it is better to use the package-provided .gpr file)

And then execute gprbuild. I have tested this and it works with your given source file.

I found that gprfile to include by first installing plplotada, and then listing all the files that package installed on my system:

sudo apt install libplplotada[Tab]
dpkg-query -L libplplotada2-dev
0
votes

My solution:

I am including my solution for those facing the same problem.

To build myfile.adb that uses plplot library write the following,

gnatmake myfile.adb -aI/usr/share/ada/adainclude/plplotada -aL/usr/lib64/ada/adalib/plplotada -cargs -I/usr/include/plplot -largs -lplplotada -lplplot

To compile myfile.adb that uses plot library write the following,

-I/usr/share/ada/adainclude/plplotada -I/usr/include/plplot myfile.adb

Before compiling, check that the libraries are there as shown above. It is applicable to linux system. Note that the above flags are long. It will be nice to have all these flags included in myfile.adb if possible.