【问题标题】:Compiling plplot with gfortran用 gfortran 编译 plplot
【发布时间】:2021-08-07 21:18:58
【问题描述】:

使用 plplot 图形库的 Gfortran 编译失败。

仅供参考:Plplot 是一个图形库,使用它可以直接从 gfortran(以及其他语言)进行绘图。

我已经安装了以下软件包(在 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

我使用以下命令更新了本地数据库:sudo updatedb。当我运行命令 locate plplot 时,我得到以下相关行(以及其他行)

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

然后我尝试编译给定here的fortran示例代码(相关部分在下面给出)

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

使用以下命令

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

pkg-config --cflags --libs plplot-fortran 的输出是

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

我得到的错误如下:

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

我需要安装任何其他软件包还是编译命令不完整?任何帮助将不胜感激。

【问题讨论】:

  • @VladimirF:在上述问题中添加了 $(pkg-config --cflags --libs plplot-fortran) 的代码和输出。由于该代码不是我的真正代码,而是一个标准示例,因此我放了一个链接。
  • 您的系统上是否存在 plfortrandemolib.mod?如果是,那么您需要在命令行中指定模块的路径。如果不是,那么您需要将模块安装在 gfortran 可以找到的位置。
  • @evets:存在以下路径/usr/lib/x86_64-linux-gnu/fortran/modules/plplot/plfortrandemolib.mod
  • @evets:尝试使用以下命令:gfortran x00f.f90 -L/usr/lib/ $(pkg-config --cflags --libs plplot-fortran)。仍然没有运气。我收到相同的错误消息。
  • @evets:终于想通了。要编译的命令是gfortran x00f.f90 -lplfortrandemolib $(pkg-config --cflags --libs plplot-fortran)。每次使用新模块时,即使使用pkg-config 命令,是否也必须单独指定每个模块?

标签: plot fortran gfortran


【解决方案1】:

为未来的 SO 用户回答我自己的问题。 上述代码正确的编译命令是

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

同时查看 VladimirF 的评论。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    相关资源
    最近更新 更多