Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG/ISSUE] "-lhdf5_hl -lhdf5" flags break compilation #37

Closed
JiaweiZhuang opened this issue Sep 9, 2019 · 6 comments
Closed

[BUG/ISSUE] "-lhdf5_hl -lhdf5" flags break compilation #37

JiaweiZhuang opened this issue Sep 9, 2019 · 6 comments
Assignees
Labels
bug Something isn't working build Related to compiling and linking

Comments

@JiaweiZhuang
Copy link
Contributor

Describe the bug

During compilation, some commands contain -lhdf5_hl -lhdf5 but don't specify the HDF5 library path via -L:

mpif90 -L/home/centos/tutorial/Code.GCHP/GCHP/Shared/Linux/lib -L/home/centos/tutorial/Code.GCHP/GCHP/Shared/Linux/lib  -o sst_sic_EIGTHdeg.x libNSIDC-OSTIA_SST-ICE_blend.a -L/home/centos/spack/opt/spack/linux-centos7-x86_64/intel-19.0.4/netcdf-fortran-4.4.5-uv5xocaoik42r6odukzzhjixymhytovx/lib -lnetcdff -L/home/centos/spack/opt/spack/linux-centos7-x86_64/intel-19.0.4/netcdf-4.7.0-5fkurucr6jdlwztewiqmqkxen4vvm7xa/lib -lnetcdf -lnetcdf -lhdf5_hl -lhdf5 -lz -lm -L/home/centos/spack/opt/spack/linux-centos7-x86_64/intel-19.0.4/netcdf-4.7.0-5fkurucr6jdlwztewiqmqkxen4vvm7xa/lib -lnetcdf -ldl -lc -lpthread -lrt  -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -lstdc++
mpif90 -L/home/centos/tutorial/Code.GCHP/GCHP/Shared/Linux/lib -L/home/centos/tutorial/Code.GCHP/GCHP/Shared/Linux/lib  -o sst_sic_QUARTdeg.x libNSIDC-OSTIA_SST-ICE_blend.a -L/home/centos/spack/opt/spack/linux-centos7-x86_64/intel-19.0.4/netcdf-fortran-4.4.5-uv5xocaoik42r6odukzzhjixymhytovx/lib -lnetcdff -L/home/centos/spack/opt/spack/linux-centos7-x86_64/intel-19.0.4/netcdf-4.7.0-5fkurucr6jdlwztewiqmqkxen4vvm7xa/lib -lnetcdf -lnetcdf -lhdf5_hl -lhdf5 -lz -lm -L/home/centos/spack/opt/spack/linux-centos7-x86_64/intel-19.0.4/netcdf-4.7.0-5fkurucr6jdlwztewiqmqkxen4vvm7xa/lib -lnetcdf -ldl -lc -lpthread -lrt  -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -lstdc++
ld: cannot find -lhdf5_hl
ld: cannot find -lhdf5
ld: cannot find -lhdf5_hl
ld: cannot find -lhdf5
gmake[13]: *** [sst_sic_EIGTHdeg.x] Error 1
gmake[13]: *** Waiting for unfinished jobs....
gmake[13]: *** [sst_sic_QUARTdeg.x] Error 1

Full compile log: compile_hdf5_error.log

This can be solved by a dirty fix that copies HDF5 libraries into NetCDF directory:

ln -s $(spack location -i hdf5)/lib/* $(spack location -i netcdf)/lib/

Successful compile log: compile_success.log

To Reproduce

The environment config is:

source $(spack location -i intel)/bin/compilervars.sh -arch intel64  # enable icc/ifort
module load intelmpi  # enable mpicc/mpifort

export I_MPI_CC=icc
export I_MPI_CXX=icpc
export I_MPI_FC=ifort
export I_MPI_F77=ifort
export I_MPI_F90=ifort

export CC=icc
export CXX=icpc
export FC=ifort
export F77=$FC
export F90=$FC

export OMPI_CC=$CC
export OMPI_CXX=$CXX
export OMPI_FC=$FC
export COMPILER=$FC
export ESMF_COMPILER=intel

export ESMF_COMM=intelmpi
export MPI_ROOT=/opt/intel/compilers_and_libraries/linux/mpi/intel64

export NETCDF_HOME=$(spack location -i netcdf)
export NETCDF_FORTRAN_HOME=$(spack location -i netcdf-fortran)

export GC_BIN="$NETCDF_HOME/bin"
export GC_INCLUDE="$NETCDF_HOME/include"
export GC_LIB="$NETCDF_HOME/lib"

export GC_F_BIN="$NETCDF_FORTRAN_HOME/bin"
export GC_F_INCLUDE="$NETCDF_FORTRAN_HOME/include"
export GC_F_LIB="$NETCDF_FORTRAN_HOME/lib"

export PATH=${NETCDF_HOME}/bin:$PATH
export PATH=${NETCDF_FORTRAN_HOME}/bin:$PATH

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${NETCDF_HOME}/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${NETCDF_FORTRAN_HOME}/lib

export ESMF_BOPT=O

Environment

@JiaweiZhuang
Copy link
Contributor Author

I saw no hard-coded -lhdf5_hl -lhdf5 in GCHP Makefile. @jimmielin suspect that the -lnetcdf -lnetcdf -lhdf5_hl -lhdf5 -lz -lm part comes from nf-config --flibs in some ESMF Makefiles. For example ESMF/build/common.mk uses

ESMF_NFCONFIG = $(shell $(ESMF_NETCDF) --prefix)/bin/nf-config

which gives you this annoying -lhdf5_hl -lhdf5:

$ $(spack location -i netcdf-fortran)/bin/nf-config --flibs
-L/home/centos/spack/opt/spack/linux-centos7-x86_64/intel-19.0.4/netcdf-fortran-4.4.5-tuuki3kp5ngtji3m54zjw3bkh7ri2num/lib -lnetcdff -L/home/centos/spack/opt/spack/linux-centos7-x86_64/intel-19.0.4/netcdf-4.7.0-sale32bbd3tize6jgjq6npfvgrfeyw65/lib -lnetcdf -lnetcdf -lhdf5_hl -lhdf5 -lz -lm

@JiaweiZhuang
Copy link
Contributor Author

JiaweiZhuang commented Sep 10, 2019

Same problem with 12.5.0. See geoschem/GCHP#17 (comment) for a log containing this HDF5 error.

@jimmielin
Copy link

I can confirm this will also be the case for GEOS-Chem Classic when generating the final geos executable. This does not impact GEOS-Chem Classic itself as it does not depend on Intel MPI (so this scenario is unlikely to break any users' installs), however there should be no reason GCC depends on -lhdf5 -lhdf5_hl.

This is specified in Makefile_header.mk in the main GEOS-Chem directory:

NC_LINK_CMD      := $(shell $(GC_F_BIN)/nf-config --flibs)

nf-config --flibs will return -lhdf5 -lhdf5_hl. Compiling without those linker flags will not break GCC so there could be a regex to patch them out of the nf-config output, for a quick fix.

@JiaweiZhuang
Copy link
Contributor Author

In a container environment (with almost no pre-installed libraries), the -lz flag (linking zlib) also breaks the build. Can be fixed by yum install zlib-devel.

JiaweiZhuang referenced this issue in JiaweiZhuang/docker_gchp Sep 11, 2019
Now 12.3.2 can be successfully compiled.
Ref: geoschem/GCHP#37 (comment)
@lizziel lizziel added bug Something isn't working build Related to compiling and linking labels Sep 17, 2019
@lizziel
Copy link
Contributor

lizziel commented Feb 26, 2020

@jimmielin @JiaweiZhuang Have either of you verified if this issue is still an open issue when using CMake? I also wonder about using the latest GCHP which has an updated ESMF.

@lizziel lizziel self-assigned this Feb 26, 2020
@lizziel
Copy link
Contributor

lizziel commented Aug 18, 2020

I am closing this issue since there has been no responses. The problematic code is in Makefiles that will be retired in the next version (13.0).

@lizziel lizziel closed this as completed Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working build Related to compiling and linking
Development

No branches or pull requests

3 participants