ASarkar
ASarkar

Reputation: 529

Compiling plplot with gfortran

Gfortran compilation fails with plplot graphics library.

FYI: Plplot is a graphics library with which one can plot directly from gfortran (among other languages).

I have installed the following packages (on Xubuntu 18.04)

sudo apt install gfortran libplplot15 libplplot-dev libplplotfortran0 plplot-driver-cairo plplot-driver-qt plplot-driver-wxwidgets plplot-driver-xwin plplot-doc

I updated the local database with the following command: sudo updatedb. When I ran the command locate plplot I get the following relevant lines (along with other lines)

/usr/lib/x86_64-linux-gnu/pkgconfig/plplot-fortran.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/plplot.pc

Then I tried to compile the fortran example code given here (relevant part is given below)

program x00f
use plfortrandemolib

integer, parameter :: NSIZE = 101

real(kind=pl_test_flt), dimension(NSIZE) :: x, y

real(kind=pl_test_flt) :: xmin = 0._pl_test_flt, xmax = 1._pl_test_flt, ymin = 0._pl_test_flt, ymax = 100._pl_test_flt
! integer          :: i
integer :: plparseopts_rc

! Prepare data to be plotted.
x = arange(NSIZE) / real(NSIZE-1,pl_test_flt)
y = ymax * x**2

! Or alternatively, using a DO-loop
!do i = 1,NSIZE
!    x(i) = real( i - 1, pl_test_flt ) / real( NSIZE - 1, pl_test_flt )
!    y(i) = ymax * x(i)**2
!enddo

! Parse and process command line arguments
plparseopts_rc = plparseopts( PL_PARSE_FULL )
if(plparseopts_rc .ne. 0) stop "plparseopts error"

! Initialize plplot
call plinit

! Create a labelled box to hold the plot.
call plenv( xmin, xmax, ymin, ymax, 0, 0 )
call pllab( "x", "y=100 x#u2#d", "Simple PLplot demo of a 2D line plot" )

! Plot the data that was prepared above.
call plline( x, y )

! Close PLplot library
call plend

end program x00f

with the following command

gfortran x00f.f90 $(pkg-config --cflags --libs plplot-fortran)

The output of pkg-config --cflags --libs plplot-fortran is

-I/usr/include/plplot -I/usr/lib/x86_64-linux-gnu/fortran/modules/plplot -I/usr/include/plplot -lplplotfortran

The error that I get is the following:

/tmp/ccAQ0C7A.o: In function `MAIN__':
x00f.f90:(.text+0x65): undefined reference to `__plfortrandemolib_MOD_arange_1'
collect2: error: ld returned 1 exit status

Do I need to install any other packages or is the compilation command is incomplete? Any help will be appreciated.

Upvotes: 0

Views: 1112

Answers (1)

ASarkar
ASarkar

Reputation: 529

Answering my own question for future SO users. The correct compilation command for the above code is

gfortran x00f.f90 -lplfortrandemolib $(pkg-config --cflags --libs plplot-fortran) 

Also check VladimirF's comment on the same.

Upvotes: 3

Related Questions