首页 文章

Fortran未明确引用'gplot_'

提问于
浏览
3

在过去的几天里,我无法获得一些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的子程序不是私有的 . 根据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还是使用手动命令编译它,我都不需要运行它 . 对不起,如果这很详细,我只想提供尽可能多的相关信息 . 感谢您提供任何帮助 .

1 回答

  • 2

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

    nm gplot.a | grep -i "gplot"
    

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

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

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

相关问题