MPAS-Dev / MPAS-Model

Repository for MPAS models and shared framework releases.
241 stars 319 forks source link

Unable to compile "init_atmosphere" core, "undefined reference to `ncmpi_open'" #1233

Closed Syize closed 1 month ago

Syize commented 1 month ago

Compile "init_atmosphere" core failed with following settings:

CORE=init_atmosphere
OPENMP=ture
make gfortran

error messages from make are:

/usr/bin/ld: /home/liurw/Apps/MPAS/src/external/SMIOL/libsmiol.a(smiol.o): in function `SMIOL_open_file':
smiol.c:(.text+0x5bb): undefined reference to `ncmpi_open'
/usr/bin/ld: smiol.c:(.text+0x5ea): undefined reference to `ncmpi_buffer_attach'
/usr/bin/ld: smiol.c:(.text+0x63b): undefined reference to `ncmpi_create'
......

These "ncmpi_*" symbol is from "libpnetcdf.a", which should be linked at the final step.

After checking the log, it seems the compile command:

mpif90 -O3 -L/usr/lib/x86_64-linux-gnu -lpnetcdf -fopenmp -o init_atmosphere_model driver/*.o -L. -ldycore -lops -lframework -L/home/liurw/Apps/MPAS/src/external/SMIOL -lsmiolf -lsmiol -I./external/esmf_time_f90 -L./external/esmf_time_f90 -lesmf_time

should be

mpif90 -O3 -fopenmp -L/usr/lib/x86_64-linux-gnu -o init_atmosphere_model driver/*.o -L. -ldycore -lops -lframework -L/home/liurw/Apps/MPAS/src/external/SMIOL -lsmiolf -lsmiol -I./external/esmf_time_f90 -L./external/esmf_time_f90 -lesmf_time -lpnetcdf

Adding -lpnetcdf to src/Makefile solve this issue.

mpas: $(AUTOCLEAN_DEPS) externals frame ops dycore drver
        $(LINKER) $(LDFLAGS) -o $(EXE_NAME) driver/*.o -L. -ldycore -lops -lframework $(LIBS) -I./external/esmf_time_f90 -L./external/esmf_time_f90 -lesmf_time -lpnetcdf

mgduda commented 1 month ago

Have you set the PNETCDF environment variable to the installation path for Parallel-netCDF?

Syize commented 1 month ago

Thanks for reply. It turns out I forget to set NETCDF, PNETCDF and PIO environment variables when building init_atmosphere core : )