I tried to compile the following Fortran code found at http://techlogbook.wordpress.com/200...-kubuntu-8-04/
program testplplot2d
use plplot
implicit none
real(plflt),dimension(6) :: x,y
real(plflt)::xmin,xmax,ymin,ymax
x=(/1,2,3,4,5,6/)
y=x**2
write(*,*) y
call plinit()
xmin=1.0
xmax=6.0
ymin=1.0
ymax=40.0
call plcol0(1)
call plenv(xmin,xmax,ymin,ymax,0,0)
call pllab('X','Y','Test 1D plot')
call plpoin(x,y,9)
call plline(x,y)
y=x**3
call plpoin(x,y,9)
call plline(x,y)
call plend()
end program testplplot2d
I used the following command in my attempt to compile the program:
gfortran -I/usr/lib/fortran/modules/plplot testplot2d.f90 -o testplot2d
However I received the a linking error message detailed below:
/tmp/cckSqEg4.o: In function `MAIN__':
testplot2d.f90:(.text+0x10c): undefined reference to `plinit_'
testplot2d.f90:(.text+0x154): undefined reference to `plcol0_'
testplot2d.f90:(开发者_开发百科.text+0x181): undefined reference to `plenv_'
testplot2d.f90:(.text+0x1a6): undefined reference to `__plplotp_MOD_pllab'
testplot2d.f90:(.text+0x248): undefined reference to `__plplot_MOD_plpoin'
testplot2d.f90:(.text+0x2e5): undefined reference to `__plplot_MOD_plline'
testplot2d.f90:(.text+0x3c6): undefined reference to `__plplot_MOD_plpoin'
testplot2d.f90:(.text+0x463): undefined reference to `__plplot_MOD_plline'
testplot2d.f90:(.text+0x46d): undefined reference to `plend_'
collect2: ld returned 1 exit status
What should I do to correct this problem? (I read the man pages for gfortran, and I believe I am using the correct option for linking against a library.)
The error messages that you show us are generated by the linker, not the compiler. I don't know gfortran so what follows may be wide of the mark
-I generally (on the Linux and Unix compilers I am familiar with) identifies a directory which contains files to be included in compilation, rather than when linking. For Fortran the .mod
files created when you compile a module have to be included during compilation.
Since you are not getting error messages telling you that the module you USE
is not found, you can work on the basis that it is being found where you tell the compiler to look.
The Linux compilers I am familiar with use the -L flag, a directory, and an abbreviated form of the library name to identify libraries to be linked. In your case I would have expected to see something like:
-L/path/to/installed/lib/files -lplplot
included in your compilation statement. How you tell gfortran to include the library at link time I do not know, but I do not see anything in your compilation statement that does tell gfortran what libraries to link.
I posted this on the ubuntuforums as well. User gmargo posted the following solution:
Install the libplplot-dev package and then compile with this command line:
gfortran testplot2d.f90 -o testplot2d $(pkg-config --cflags --libs plplotd-f95)
Thank you @belisarius and @High-Performance-Mark for your efforts.
You have missing external references.
The page from where you got the code starts:
I installed libplplot from Kubuntu Adept package manager, and chose “libplplot-fortran9″ package.
I guess you should do the same.
精彩评论