Fortran 未识别的对 'gplot_' 的引用

标签 fortran gnuplot fortran90 gfortran fortran95

在过去的几天里,我无法获得一些要编译的 Fortran 代码(请注意,我不是这段代码的作者,我是从 author's web page 下载的。它是开源的)。主程序名为 multitaper.f95,它使用名为 plot 和 spectra 的模块,以及名为 mwlib.a 和 gplot.a 的库。为了简单起见,我将 multitaper.f95、mwlib.a、gplot.a、plot.mod 和 spectra.mod 都放在同一个目录中。绘图和光谱模块分别由 gplot.f90 和 mtspec.f95 制成,它们也与其他所有内容位于同一目录中。但是,以下命令会产生一条错误消息:

gfortran multitaper.f95 mtspec.f95 gplot.f90 -o multitaper -L gplot.a mwlib.a
/tmp/ccBJzwYI.o: In function `MAIN__':
multitaper.f95:(.text+0x1111): undefined reference to `gplot_'
multitaper.f95:(.text+0x11af): undefined reference to `gplot_'
multitaper.f95:(.text+0x1246): undefined reference to `gplot_'
collect2: error: ld returned 1 exit status

gplot.f90的内容是

module plot

!
!  Interface to allow for x or y to be a matrix, and plot each vector
!  of y against x. The matrix is given by horizontal vectors, y(:,1) is 
!  the first vector.
!   April 22 2005
!       Allowing to also use real(4) and real(8) units.
!

!
!  Interface
!           dvv vector vs vector
!       dvm vector vs matrix
!       dmm matrix vs matrix
!       rvv real(4) vector vs vector
!       rvm real(4) vector vs matrix
!       rmm real(4) matrix vs matrix
!

interface gnuplot
  module procedure gnuplot_dvv, gnuplot_dvm, gnuplot_dmm,              &
                   gnuplot_rvv, gnuplot_rvm, gnuplot_rmm,              &
                   gnuplot_rv,  gnuplot_rm      
end interface gnuplot

! The subroutines

contains

!The NEW GNUPlot subroutines

include 'gnuplot.f90'

end module plot

!======================================================================

Gnuplot.f90 有 3700 行代码,所以我不会在这里发布。我是 Fortran 的新手,所以如果我只是在做一些愚蠢的事情,我会提前道歉。但是,几天来我一直在互联网上寻找解决方案,但结果并不多。我找到了这个 ( Fortran compilation error - undefined reference ),但是 multitaper.f95 有一个用于光谱和绘图的 use 语句,并且 gplot 和 gnuplot.f90 的子例程不是私有(private)的。根据https://gcc.gnu.org/wiki/GFortranGettingStartedhttp://www.oceanographers.net/forums/showthread.php?378-How-to-make-a-FORTRAN-library据我所知,我的终端咒语应该有效。为了确定,我继续尝试分别编译 gplot.f90 和 mtspec.f95,并将目标文件提供给 gfortran 命令,但这没有任何改变。我还尝试将 gplot.f90 和 gnuplot.f90 的文件扩展名更改为 f95,因为其中不应该有任何会导致版本冲突的内容,但这又一次产生了相同的错误消息。为了以防万一,我还尝试在 -L 命令后包含目录的完整路径,但得到了相同的错误消息。

Makefile 并没有更好地工作,而且我承认我对它们以及它们的工作方式知之甚少。当我运行 make 命令时,出现以下错误,就像我尝试手动编译它时一样。 Makefile文件内容如下:

# Location of files

DIR = /N/u/rccaton/Quarry/EarthHum/mtspec/program
LIB = /N/u/rccaton/Quarry/EarthHum/mtspec/program
#LIB2 = 

# Objects and Libraries

OBJS = $(LIB)/mwlib.a \
       $(LIB)/gplot.a \
#       /Applications/Absoft/lib/libU77.a


# Module locations

MODS = $(LIB)
MODS2 = $(LIB)

# Compiler
#FC =      g95
#FC =      f95
FC = gfortran

# Compiler flags
#   none
FLAGS =
#   debug
#FFLAGS = -g 

# Module flag

# Sun Compiler
#MFLAG = -M
# Nag Compiler
#MFLAG = -i
MFLAG = -I
# Absoft Compiler
#MFLAG = -p
# g95 compiler
#MFLAG = -I

MODULE = $(MFLAG)$(MODS) # $(MFLAG)$(MODS2) 

# Compile

all : multitaper

%:      %.f95 $(OBJS)
    $(FC) $(FFLAGS) $(MODULE) $< $(OBJS) -o $@


# Clean

clean : 
    rm multitaper

归根结底,最终是使用 makefile 还是手动命令编译它对我来说是不同的,我只需要它运行即可。抱歉,如果这很冗长,我只想提供尽可能多的相关信息。感谢您提供的任何帮助。

最佳答案

我建议找出从 gplot.a 导出的符号

nm gplot.a | grep -i "gplot"

并相应地更改编译器标志,搜索 gfortran 标志:

-fno-underscoring
-fsecond-underscore
-fcase-*

如果没有帮助,请作者给你正确的 MakeFile。

关于Fortran 未识别的对 'gplot_' 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24169978/

相关文章:

python - 使用 ctypes 在 Python 中使用 Fortran 可选参数

Gnuplot 细粒度范围(网格)

gnuplot - Gnuplot 中刻度线的位置

compiler-errors - 系统找不到指定的文件-在SciTE中编译

c++ - 如何使用 MPI 在不同的处理器上使用相同的数组

c - Fortran 的准确性和速度与 C 的对比

c - fortran 程序的 mtrace

math - 基本算术给出奇怪的值

plot - 如何从 stdin 读取数据到 gnuplot 并绘制相同的数据两次

module - Fortran 模块中类型之间的循环依赖