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

Undefined Symbols Problem

whannah

Member
I've been trying to build the CESM on a macbook pro for a week now and I keep running into different versions of what appears to be the same problem when linking the netcdf libraries.

here's some output I get when trying to configure with

sudo $camcfg/configure -dyn eul
-target_os linux
-fc gfortran
-fflags '-g -fno-range-check -ffree-line-length-none '
-ldflags '-lcurl '
-hgrid 64x128
-nlev 30 -scam
-nospmd -nosmp
-debug -v -test
-ice sice
-lnd slnd
-nc_lib $NC_DIR/lib
-nc_inc $NC_DIR/include
-nc_mod $NC_DIR/include
-mpi_lib $MP_DIR/lib
-mpi_inc $MP_DIR/include


using gfortran
Test linking to NetCDF library... **** FAILED ****
Issued the command:
gmake -f /Users/whannah/CESM/scam_sim_2/Makefile test_nc 2>&1

The output was:
cat: Srcfiles: No such file or directory
/Users/whannah/CESM/scam_sim_2/Makefile:875: /Users/whannah/CESM/scam_sim_2/configure-tests/Depends: No such file or directory
/Users/whannah/CESM/cesm1_0_2/models/atm/cam/bld/mkSrcfiles > /Users/whannah/CESM/scam_sim_2/configure-tests/Srcfiles
/Users/whannah/CESM/cesm1_0_2/models/atm/cam/bld/mkDepends Filepath Srcfiles > /Users/whannah/CESM/scam_sim_2/configure-tests/Depends
gfortran -c -ffree-form -I. -I/Users/whannah/CESM/scam_sim_2/configure-tests -I/Users/whannah/netcdf4/include -I/Users/whannah/netcdf4/include -DNO_SHR_VMATH -DSEQ_MCT -DDUST -DPROGSSLT -DMODAL_AERO -DMODAL_AERO_3MODE -DFORTRANUNDERSCORE -DCO2A -DMAXPATCH_PFT=numpft+1 -DLSMLAT=1 -DLSMLON=1 -DPLON=1 -DPLAT=1 -DPLEV=30 -DPCNST=25 -DPCOLS=1 -DPTRM=1 -DPTRN=1 -DPTRK=1 -DTROPCHEM -D_USEBOX -D_NETCDF -DLINUX -DNO_R16 -fno-range-check -ff2c -g -frecursive -fbounds-check -DHIDE_MPI -D_MPISERIAL -g -fno-range-check -ffree-line-length-none test_nc.F90
gfortran -o test_nc test_nc.o -L/Users/whannah/netcdf4/lib -lnetcdf -lcurl
Undefined symbols for architecture x86_64:
"___netcdf_MOD_nf90_create", referenced from:
_MAIN__ in test_nc.o
"___netcdf_MOD_nf90_strerror", referenced from:
_MAIN__ in test_nc.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
gmake: *** [test_nc] Error 1



I get similar issues when using mpif90 as the compiler. I also have tried using create_newcase and going through the steps described on this blog post

http://www.easterbrook.ca/steve/?p=1791

I can't find any general information about what these error messages are telling me. I've contacted someone at Unidata but they aren't quite sure how to fix this issue either.

any help or suggestions would be appreciated.

Thanks,
Walter
 

whannah

Member
ok, just figured it out!

I went into the directory where I had installed the NETCDF libraries and typed:

nm libnetcdf.a | grep "___netcdf_MOD_nf90_copy_att"

In order to search for one of the missing symbols, but it wasn't in that library. Then I noticed that there was two similarly named files > libnetcdf.a and libnetcdff.a (notice the double "f")

So then when I typed this:

nm libnetcdff.a | grep "___netcdf_MOD_nf90_copy_att"

I got

0000000000046230 T ___netcdf_MOD_nf90_copy_att

So then, in the "Macros.generic_linux_intel" file (in the case directory), I added this line

USER_LDFLAGS := -lcurl -L/Users/whannah/netcdf4/lib/ -lnetcdff

I went back and tried to build again and it successfully linked up to all the right NETCDF libraries.

After a week of working on this I can't believe it was so simple! I still don't understand why the compiler didn't try looking in those libraries in the first place. Maybe it's because I'm using the newest version of the NETCDF libraries? who knows.
 

eaton

CSEG and Liaisons
The CESM scripts currently only add -lnetcdf to the link command. The NetCDF build has allowed the creation of a separate library for the Fortran interfaces, libnetcdff, for quite a while, but unless specifically requested, the separate Fortran library was only created when shared libraries were built. Building shared libraries has not been the default until the netcdf-4.1.2 release. So we are in a transition period where it will start to become more common that -lnetcdff will need to be added to the link command.
 
Top