首页 > 解决方案 > /usr/bin/ld: 找不到 -lnetcdf?

问题描述

首先,这是我在这里的第一个问题。如果我犯了错误,我很抱歉。顺便说一句,我是 Fortran 的新手。我想编译“MMIF”模型,该模型有一个编译器“makefile”。我编辑了我的“makefile”,但我有一条错误消息。当我使用该make命令时,我收到此错误:

...
    /usr/bin/ld: cannot find -lnetcdf
    collect2: error: ld returned 1 exit status
    makefile:62: recipe for target 'mmif' failed
    make: *** [mmif] Error 1

当我检查位置时,我意识到 libnetcdf.a 丢失了。我不知道是否需要它来运行“makefile”。你能帮我解决这种情况吗?

...
/usr/lib/x86_64-linux-gnu/libnetcdff.a                
/usr/lib/x86_64-linux-gnu/libnetcdff.so      
/usr/lib/x86_64-linux-gnu/libnetcdff.so.6    
/usr/lib/x86_64-linux-gnu/libnetcdff.so.6.1.1
/usr/lib/x86_64-linux-gnu/libnetcdf.settings 
/usr/lib/x86_64-linux-gnu/libnetcdf.so       
/usr/lib/x86_64-linux-gnu/libnetcdf.so.13
...   

更新 1

谢谢你帮助和指导我。我-lnetcdf改为-lnetcdff. 它有效,但我现在有另一个问题。我收到了很多“未定义的引用..”。现在,我正在努力解决这些问题。

错误代码

/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_put_att_text_':
(.text+0xb3): undefined reference to `nc_put_att_text'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_put_att_text_a_':
(.text+0x193): undefined reference to `nc_put_att_text'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_put_att_int1_':
(.text+0x277): undefined reference to `nc_put_att_schar'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_put_att_int2_':
(.text+0x357): undefined reference to `nc_put_att_short'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_put_att_int_':
(.text+0x437): undefined reference to `nc_put_att_int'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_put_att_real_':
(.text+0x517): undefined reference to `nc_put_att_float'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_put_att_double_':
(.text+0x5f7): undefined reference to `nc_put_att_double'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_get_att_text_':
(.text+0x745): undefined reference to `nc_get_att_text'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_get_att_text_a_':
(.text+0x846): undefined reference to `nc_get_att_text'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_get_att_int1_':
(.text+0x916): undefined reference to `nc_get_att_schar'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_get_att_int2_':
(.text+0x9e6): undefined reference to `nc_get_att_short'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_get_att_int_':
(.text+0xab6): undefined reference to `nc_get_att_int'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_get_att_real_':
(.text+0xb86): undefined reference to `nc_get_att_float'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_attio.o): In function `nf_get_att_double_':
(.text+0xc56): undefined reference to `nc_get_att_double'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_create_':
(.text+0xa1): undefined reference to `nc_create'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf__create_':
(.text+0x19a): undefined reference to `nc__create'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf__create_mp_':
(.text+0x292): undefined reference to `nc__create_mp'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_open_':
(.text+0x371): undefined reference to `nc_open'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf__open_':
(.text+0x45d): undefined reference to `nc__open'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf__open_mp_':
(.text+0x557): undefined reference to `nc__open_mp'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_open_mem_':
(.text+0x63c): undefined reference to `nc_open_mem'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_inq_path_':
(.text+0x78d): undefined reference to `nc_inq_path'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_set_fill_':
(.text+0x8ba): undefined reference to `nc_set_fill'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_set_default_format_':
(.text+0x910): undefined reference to `nc_set_default_format'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_delete_':
(.text+0xa3a): undefined reference to `nc_delete'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_delete_mp_':
(.text+0xb02): undefined reference to `nc_delete_mp'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_inq_base_pe_':
(.text+0xb60): undefined reference to `nc_inq_base_pe'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_redef_':
(.text+0x943): undefined reference to `nc_redef'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_enddef_':
(.text+0x953): undefined reference to `nc_enddef'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf__enddef_':
(.text+0x96f): undefined reference to `nc__enddef'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_sync_':
(.text+0x983): undefined reference to `nc_sync'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_abort_':
(.text+0x993): undefined reference to `nc_abort'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_close_':
(.text+0x9a3): undefined reference to `nc_close'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_control.o): In function `nf_set_base_pe_':
(.text+0xb35): undefined reference to `nc_set_base_pe'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_dim.o): In function `nf_def_dim_':
(.text+0xb7): undefined reference to `nc_def_dim'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_dim.o): In function `nf_inq_dim_':
(.text+0x24c): undefined reference to `nc_inq_dim'
(.text+0x2a6): undefined reference to `nc_inq_dim'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_dim.o): In function `nf_inq_dimid_':
(.text+0x45d): undefined reference to `nc_inq_dimid'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_dim.o): In function `nf_inq_dimlen_':
(.text+0x4c9): undefined reference to `nc_inq_dimlen'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_dim.o): In function `nf_inq_dimname_':
(.text+0x63f): undefined reference to `nc_inq_dimname'
(.text+0x691): undefined reference to `nc_inq_dimname'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_dim.o): In function `nf_rename_dim_':
(.text+0x82e): undefined reference to `nc_rename_dim'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_genvar.o): In function `nf_def_var_':
(.text+0x111): undefined reference to `nc_def_var'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_genvar.o): In function `nf_inq_varndims_':
(.text+0x1a5): undefined reference to `nc_inq_varndims'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_genvar.o): In function `nf_inq_var_':
(.text+0x2f8): undefined reference to `nc_inq_varndims'
(.text+0x363): undefined reference to `nc_inq_var'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_genvar.o): In function `nf_inq_vardimid_':
(.text+0x550): undefined reference to `nc_inq_varndims'
(.text+0x59a): undefined reference to `nc_inq_vardimid'
(.text+0x611): undefined reference to `nc_inq_vardimid'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_genvar.o): In function `nf_inq_varid_':
(.text+0x6cf): undefined reference to `nc_inq_varid'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_genvar.o): In function `nf_inq_varname_':
(.text+0x7e9): undefined reference to `nc_inq_varname'
(.text+0x831): undefined reference to `nc_inq_varname'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_genvar.o): In function `nf_inq_vartype_':
(.text+0x955): undefined reference to `nc_inq_vartype'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_genvar.o): In function `nf_inq_varnatts_':
(.text+0x9a5): undefined reference to `nc_inq_varnatts'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_genvar.o): In function `nf_rename_var_':
(.text+0xa6e): undefined reference to `nc_rename_var'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_genvar.o): In function `nf_copy_var_':
(.text+0xaaa): undefined reference to `nc_copy_var'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_text_':
(.text+0x3d): undefined reference to `nc_inq_varndims'
(.text+0x139): undefined reference to `nc_put_vara_text'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_text_a_':
(.text+0x1cd): undefined reference to `nc_inq_varndims'
(.text+0x2c9): undefined reference to `nc_put_vara_text'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_int1_':
(.text+0x35d): undefined reference to `nc_inq_varndims'
(.text+0x459): undefined reference to `nc_put_vara_schar'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_int2_':
(.text+0x4ed): undefined reference to `nc_inq_varndims'
(.text+0x5e9): undefined reference to `nc_put_vara_short'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_int_':
(.text+0x67d): undefined reference to `nc_inq_varndims'
(.text+0x779): undefined reference to `nc_put_vara_int'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_real_':
(.text+0x80d): undefined reference to `nc_inq_varndims'
(.text+0x909): undefined reference to `nc_put_vara_float'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_double_':
(.text+0x99d): undefined reference to `nc_inq_varndims'
(.text+0xa99): undefined reference to `nc_put_vara_double'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_':
(.text+0xb2d): undefined reference to `nc_inq_varndims'
(.text+0xc29): undefined reference to `nc_put_vara'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_text_':
(.text+0xd31): undefined reference to `nc_inq_varndims'
(.text+0xe3a): undefined reference to `nc_get_vara_text'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_text_a_':
(.text+0xefd): undefined reference to `nc_inq_varndims'
(.text+0xff9): undefined reference to `nc_get_vara_text'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_int1_':
(.text+0x108d): undefined reference to `nc_inq_varndims'
(.text+0x1189): undefined reference to `nc_get_vara_schar'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_int2_':
(.text+0x121d): undefined reference to `nc_inq_varndims'
(.text+0x1319): undefined reference to `nc_get_vara_short'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_int_':
(.text+0x13ad): undefined reference to `nc_inq_varndims'
(.text+0x14a9): undefined reference to `nc_get_vara_int'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_real_':
(.text+0x153d): undefined reference to `nc_inq_varndims'
(.text+0x1639): undefined reference to `nc_get_vara_float'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_double_':
(.text+0x16cd): undefined reference to `nc_inq_varndims'
(.text+0x17c9): undefined reference to `nc_get_vara_double'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_':
(.text+0x185d): undefined reference to `nc_inq_varndims'
(.text+0x1959): undefined reference to `nc_get_vara'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_text_':
(.text+0x7e): undefined reference to `nc_put_vara_text'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_text_a_':
(.text+0x20e): undefined reference to `nc_put_vara_text'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_int1_':
(.text+0x39e): undefined reference to `nc_put_vara_schar'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_int2_':
(.text+0x52e): undefined reference to `nc_put_vara_short'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_int_':
(.text+0x6be): undefined reference to `nc_put_vara_int'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_real_':
(.text+0x84e): undefined reference to `nc_put_vara_float'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_double_':
(.text+0x9de): undefined reference to `nc_put_vara_double'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_put_vara_':
(.text+0xb6e): undefined reference to `nc_put_vara'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_text_':
(.text+0xd72): undefined reference to `nc_get_vara_text'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_text_a_':
(.text+0xf3e): undefined reference to `nc_get_vara_text'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_int1_':
(.text+0x10ce): undefined reference to `nc_get_vara_schar'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_int2_':
(.text+0x125e): undefined reference to `nc_get_vara_short'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_int_':
(.text+0x13ee): undefined reference to `nc_get_vara_int'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_real_':
(.text+0x157e): undefined reference to `nc_get_vara_float'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_double_':
(.text+0x170e): undefined reference to `nc_get_vara_double'
/usr/lib/x86_64-linux-gnu/libnetcdff.a(nf_varaio.o): In function `nf_get_vara_':
(.text+0x189e): undefined reference to `nc_get_vara'
collect2: error: ld returned 1 exit status
makefile:62: recipe for target 'mmif' failed
make: *** [mmif] Error 1

生成文件

#
# Makefile for MMIF VERSION 3.4.1 2019-03-11
#
# Edit this file to un-comment the section for your compiler.  
# You will also need to edit the line that specifies where to find the 
# NetCDF libraries, which must be compiled by the same compiler.
# The directory "netcdf.4.1.1-mingw" is used to commpile under MS Windows.
# It was compiled using MinGW version 20110802, see http://www.mingw.org, 
# and the script compile_netcdf_mingw.sh.
#
# PGI started linking with the OpenMP library by default in their 11.0 release,
# so that users would be able to use CPU binding even with serial code.  
# Adding "-mp=nonuma -nomp" to FFLAGS fixes "can't find libnuma.so" problems.

# PGI Fortran:
# FC = pgf90
# FFLAGS = -g -fast -Mlfs           # -Mlfs is default on for x86_64
# FFLAGS += -Mbounds              # for bounds checking/debugging
# FFLAGS += -Bstatic_pgi            # to use static PGI libraries
# FFLAGS += -Bstatic                # to use static netCDF libraries
# FFLAGS += -mp=nonuma -nomp        # fix for "can't find libnuma.so"
# NETCDF = /usr/local/src/netcdf-4.1.1.pgi

# GNU gfortran (Windows or Linux, just set NETCDF below correctly)
FC = gfortran
FFLAGS = -g -Wall
FFLAGS += -fbounds-check          # for bounds checking/debugging
FFLAGS += -static                 # to use static libraries
NETCDF = /usr

# Intel Fortran:
#FC = ifort
#FFLAGS = -O2 -align dcommons -ipo
#FFLAGS += -static                 # to use static libraries
#NETCDF = /path/to/netcdf-4.1.1.ifort

# NETCDF values that are the same for all compilers
INCL = -I$(NETCDF)/include
LIBS = -L/usr/lib/x86_64-linux-gnu -lnetcdff

PROGRAM = mmif

TODAY   = 2019-03-11
VERSION = 3.4.1
NEWTAG  = 3.4.1 2019-03-11
OLDTAG  = 3.4.1 2019-03-01

MODULES = met_fields.f90 functions.f90 module_llxy.f90 wrf_netcdf.f90     \
    parse_control.f90

SOURCES = aggregate.f90 avg_zface.f90 cloud_cover.f90 interpolate.f90     \
    landuse.f90 mmif.f90 output_aercoare.f90 output_aermet.f90        \
    output_calmet.f90 output_onsite.f90 output_scichem.f90            \
    pasquill_gifford.f90 pbl_height.f90 read_mm5.f90 read_wrf.f90     \
    sfc_layer.f90 timesubs.f90 

OBJECTS = $(SOURCES:.f90=.o)
MODOBJS = $(MODULES:.f90=.o)
MODMODS = $(MODULES:.f90=.mod)

$(PROGRAM): $(MODOBJS) $(OBJECTS)
    $(FC) $(FFLAGS) $(MODOBJS) $(OBJECTS) $(LIBS) -o $@

%.o : %.f90 
    $(FC) $(FFLAGS) $(INCL) -c $< -o $@

install: $(PROGRAM)
    cp $(PROGRAM) /usr/local/bin

update_version: 
    sed -i "s|VERSION $(OLDTAG)|VERSION $(NEWTAG)|g" \
        *.f90 README.txt makefile makefile.windows mmif_change_log.txt

distro: 
    mmif --sample > mmif.inp
    unix2dos *.f90 *.sh makefile.windows old_compile.bat README*.txt mmif.inp
    zip -j MMIFv$(VERSION)_$(TODAY).zip \
        mmif.exe mmif mmif.inp *.f90 *.sh makefile \
        makefile.windows old_compile.bat README*.txt \
        MMIFv$(VERSION)_Users_Manual.pdf \
        mmif_change_log.txt test_problems/*/*.inp
    dos2unix *.f90

test_pkg: 
    zip -r MMIFv$(VERSION)_test_problems.zip \
        test_problems -x \*/wrf/\* \*/mm5/\*

test_pkg_mm5+wrf:
    zip -r MMIF_test_problems_mm5+wrf.zip \
        test_problems/wrf \
        test_problems/mm5

clean:
    rm $(MODMODS) $(MODOBJS) $(OBJECTS) $(PROGRAM)

图书馆

-------
This netCDF 4.6.0 has been built with the following features: 

  --cc        -> /usr/bin/cc
  --cflags    -> -I/usr/include -I/usr/include/hdf5/serial
  --libs      -> -L/usr/lib/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu/hdf5/serial -lnetcdf -lhdf5_hl -lhdf5 -lpthread -lsz -lz -ldl -lm -lcurl

  --has-c++   -> no
  --cxx       -> 

  --has-c++4  -> no
  --cxx4      -> 

  --has-fortran-> yes
  --fc        -> gfortran
  --fflags    -> -I/usr/include
  --flibs     -> -L/usr/lib -lnetcdff -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -lnetcdf -lnetcdf
  --has-f90   -> no
  --has-f03   -> yes

  --has-dap   -> yes
  --has-dap2  -> yes
  --has-dap4  -> yes
  --has-nc2   -> yes
  --has-nc4   -> yes
  --has-hdf5  -> yes
  --has-hdf4  -> no
  --has-logging-> no
  --has-pnetcdf-> no
  --has-szlib -> no
  --has-cdf5 -> no
  --has-parallel-> no

  --prefix    -> /usr
  --includedir-> /usr/include
  --libdir    -> /usr/lib/x86_64-linux-gnu
  --version   -> netCDF 4.6.0

标签: makefilefortranlinker-errorsunresolved-external

解决方案


推荐阅读