【问题标题】:Error: undefined reference to NetCDF functions错误:对 NetCDF 函数的未定义引用
【发布时间】:2017-02-27 11:49:30
【问题描述】:

背景

我正在编译 MCIP,这意味着 centos 5.9 系统中的气象化学接口处理器。

我使用 gcc -version 4.9 来实现这个过程。

设置

这是 ~/.bashrc 中的一些配置设置:

export DIR=/disk2/hyf/lib ## All lib ar installed under this path
# NetCDF setting
export PATH="$DIR/netcdf/bin:$PATH"
export NETCDF="$DIR/netcdf"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$NETCDF/lib     
# IOAPI 
export BIN=Linux2_x86_64gfort
export BASEDIR=/disk2/hyf/backup/software/ioapi
export PATH=$DIR/ioapi-3.1/bin:$PATH
export LD_LIBRARY_PATH=$DIR/ioapi-3.1/lib:$LD_LIBRARY_PATH
# Set M3LIB for the model
export M3LIB=/disk2/hyf/cmaq/CMAQv5.1/lib

我还为 CMAQ 模型做软链接,如下所示:
ln -s $NETCDF $(M3LIB)/x86_64/gcc/netcdf ln -s $IOAPI $(M3LIB)/x86_64/gcc/ioapi

生成文件

这是 Makefile 中的一些子程序:

 # Requirements: set M3LIB before running this script

.SUFFIXES:
.SUFFIXES: .o .f90 .F90

MODEL = mcip.exe

#...gfortran
FC      = gfortran
NETCDF = $(M3LIB)/netcdf
IOAPI_ROOT = $(M3LIB)/ioapi
FFLAGS  = -O3 -gdwarf-2 -gstrict-dwarf -I$(NETCDF)/include -   I$(IOAPI_ROOT)/include \
      -ffpe-trap='invalid','zero','overflow','underflow'
##FFLAGS        = -g -O0  \
      -ffpe-trap='invalid','zero','overflow','underflow'  \
      -I$(NETCDF)/include -I$(IOAPI_ROOT)/include
LIBS    = -L$(IOAPI_ROOT)/lib -lioapi  \
      -L$(NETCDF)/lib -lnetcdf -lgomp

DEFS   =

MODULES =\
 const_mod.o \
 const_pbl_mod.o \
 coord_mod.o \
 date_time_mod.o \
 date_pack_mod.o \
 files_mod.o \
 groutcom_mod.o \
 luvars_mod.o \
 mcipparm_mod.o \
 mcoutcom_mod.o \
 mdoutcom_mod.o \
 metinfo_mod.o \
 metvars_mod.o \
 vgrd_mod.o \
 wrf_netcdf_mod.o \
 xvars_mod.o \
 sat2mcip_mod.o

OBJS =\
 mcip.o \
 alloc_ctm.o \
 alloc_met.o \
 alloc_x.o \
 bcldprc_ak.o \
 blddesc.o \
 chkwpshdr.o \
 chkwrfhdr.o \
 close_files.o \
 collapx.o \
 comheader.o \
 cori.o \
 dealloc_ctm.o \
 dealloc_met.o \
 dealloc_x.o \
 detangle_soil_px.o \
 e_aerk.o \
 dynflds.o \
 getgist.o \
 getluse.o \
 getmet.o \
 getpblht.o \
 getsdt.o \
 getversion.o \
 graceful_stop.o \
 gridout.o \
 init_io.o \
 init_met.o \
 init_x.o \
 julian.o \
 layht.o \
 ll2xy_lam.o \


 .......

错误

ma​​ke 之后的输出显示如下:

make[1]: Entering directory `/disk2/hyf/cmaq/CMAQv5.1/scripts/mcip/src'
gfortran -g -O0 -gdwarf-2 -gstrict-dwarf \ 
         -I/disk2/hyf/cmaq/CMAQv5.1/lib/x86_64/gcc/netcdf/include \      
         -I/disk2/hyf/cmaq/CMAQv5.1/lib/x86_64/gcc/ioapi/include  -c const_mod.f90
......

chkwpshdr.o: In function `chkwpshdr_':
/disk2/hyf/cmaq/CMAQv5.1/scripts/mcip/src/chkwpshdr.f90:109: \    
 undefined reference to `__netcdf_MOD_nf90_get_att_one_fourbyteint'

 (a lot of these code showing the same mistake 'undefined reference')  

 /disk2/hyf/cmaq/CMAQv5.1/lib/x86_64/gcc/ioapi/lib/libioapi.a(open3.o): In    
 function `open3_':
 open3.F:(.text+0x1531): undefined reference to `ncclos_'
 .........

我认为编译器在某些情况下可能会与 .F 和 .f90 文件发生冲突。但我不知道为什么。 gcc 已经成功安装并定义了 $PATH。

【问题讨论】:

  • 为什么这个标签是 C++ 而不是 Fortran?
  • 对不起,网站系统一开始就推荐了'c++'。
  • 这是错误链接的netcdf。你有哪个版本的 NetCDF?它安装在哪里?
  • 我使用 netcdf-version 4.13(netcdf-c 和 fortran 结合的最后一个版本)。我把它安装在另一个地方,ln -s $netcdf_PATH $(M3LIB)/x86_64/gcc/netcdf
  • netcdf 应该安装正确。因为其他模型已经很好地遵守了。

标签: linux fortran linker-errors gfortran netcdf


【解决方案1】:

我遇到了同样的问题,我必须通过在 MCIP makefile 的 LIBS 选项中添加 -lnetcdff 和 -lnetcdf(按此顺序)来解决它。确保 NETCDF 变量指向系统中安装 netcdf 的正确路径。

【讨论】:

  • 感谢您的回答。我稍后会检查它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-08
  • 1970-01-01
  • 2017-07-10
  • 2013-08-20
相关资源
最近更新 更多