Scheduled Downtime
On Tuesday 24 October 2023 @ 5pm MT the forums will be in read only mode in preparation for the downtime. On Wednesday 25 October 2023 @ 5am MT, this website will be down for maintenance and expected to return online later in the morning.
Normal Operations
The forums are back online with normal operations. If you notice any issues or errors related to the forums, please reach out to help@ucar.edu

CICE compile undefined but referenced

wangxiong

New Member
hi,everyone. i am a beginner in CICE and currently tring to compile CICE in serial and have some problem. I am using gcc and gfortran to compile CICE.I am gonna put some brief error message below. Any suggestion may help a lot. Thanks.

ERROR MESSAGE:
gfortran -o /home/wangxiong/mycase2/run/cice CICE.o CICE_FinalMod.o CICE_InitMod.o CICE_RunMod.o ice_arrays_column.o ice_blocks.o ice_boundary.o ice_broadcast.o ice_calendar.o ice_communicate.o ice_constants.o ice_diagnostics.o ice_diagnostics_bgc.o ice_distribution.o ice_domain.o ice_domain_size.o ice_dyn_eap.o ice_dyn_evp.o ice_dyn_evp_1d.o ice_dyn_shared.o ice_exit.o ice_fileunits.o ice_flux.o ice_flux_bgc.o ice_forcing.o ice_forcing_bgc.o ice_gather_scatter.o ice_global_reductions.o ice_grid.o ice_history.o ice_history_bgc.o ice_history_drag.o ice_history_mechred.o ice_history_pond.o ice_history_shared.o ice_history_write.o ice_init.o ice_init_column.o ice_kinds_mod.o ice_read_write.o ice_reprosum.o ice_restart.o ice_restart_column.o ice_restart_driver.o ice_restart_shared.o ice_restoring.o ice_shr_reprosum86.o ice_spacecurve.o ice_state.o ice_step_mod.o ice_timers.o ice_transport_driver.o ice_transport_remap.o icepack_aerosol.o icepack_age.o icepack_algae.o icepack_atmo.o icepack_brine.o icepack_firstyear.o icepack_flux.o icepack_intfc.o icepack_itd.o icepack_kinds.o icepack_mechred.o icepack_meltpond_cesm.o icepack_meltpond_lvl.o icepack_meltpond_topo.o icepack_mushy_physics.o icepack_ocean.o icepack_orbital.o icepack_parameters.o icepack_shortwave.o icepack_therm_0layer.o icepack_therm_bl99.o icepack_therm_itd.o icepack_therm_mushy.o icepack_therm_shared.o icepack_therm_vertical.o icepack_tracers.o icepack_warnings.o icepack_zbgc.o icepack_zbgc_shared.o icepack_zsalinity.o -L/usr/lib64 -lnetcdf

ice_domain.o:in function ‘__ice_domain_MOD_init_domain_distribution’:
ice_domain.F90: (.text+0x2772):‘__netcdf_MOD_nf90_open’ undefined but referenced
ice_domain.F90: (.text+0x27a1):‘__netcdf_MOD_nf90_inq_varid’ undefined but referenced
ice_domain.F90: (.text+0x27c9):‘__netcdf_MOD_nf90_get_var_2d_eightbytereal’ undefined but referenced
ice_domain.F90: (.text+0x27d6):‘__netcdf_MOD_nf90_close’ undefined but referenced


collect2: error:ld returned 1
gmake: *** [/home/wangxiong/mycase2/run/cice] error 1
 

Philippe Blain

New Member
Hi wangxiong,

You have an error at link time (ld returned 1, ld is the system linker on Linux). This error means that the linker does not know where to find the symbols (subroutines) that it complains about (__netcdf_MOD_nf90_open, etc). For the linker to find the symbols you need 2 things:
1. tell the linker that the code uses the NetCDF library as well as its Fortran bindings. In your Macros file (configuration/scripts/machines/Macros.yourmachine_gnu), you should have this line (make sure it is not commented, i.e. it should *not* start with #):

Makefile:
SLIBS   := -L$(LIB_NETCDF) -lnetcdff -lnetcdf
2. tell the linker where to find the NetCDF libraries on your machine. On GitHub, you wrote that you installed the NetCDF library at /usr/lib64/gfortran/modeles. At that location you should have a lib folder with 'libnetcdff.so' and 'libnetcdf.so'. If so, add this to your Macros file *before* the SLIBS := ... line:
Makefile:
LIB_NETCDF := /usr/lib64/gfortran/modeles/lib/

Hope this helps,
Philippe.
 

wangxiong

New Member
Hi Philippe.

Thank you so much for your detailed reply.I carefully looked into the 2 things you mentioned and found out I did most as same as you advised except on the line :
SLIBS := -L$(LIB_NETCDF) -lnetcdff -lnetcdf
I did not have -lnetcdff on this line. And after I added the -lnetcdff on the line just like you wrote and tried another time, this time, it returns the message ./cice.build: COMPILE SUCCESSFUL. But util now I do not know why the lack of -lnetcdff may cause this error. Even so, I am pretty thrilled to get this problem solved with your help since this problem has struck me for over two weeks before I found this forum.

Again, thank so much for your help.
 

Philippe Blain

New Member
Glad to know I could help!
Basically -lnetcdff is required to use the Fortran NetCDF bindings. For other software written in C instead of Fortran -lnetcdf would have been enough.
Cheers!
 
Top