Closed edwardhartnett closed 4 years ago
Thanks for reporting this. We have mostly tested this for the combination of NCEPLIBS-external and NCEPLIBS. The version of findNetCDF.cmake in NCEPLIBS relies on pkg-config. Can you check that the pkg-config for netCDF and netCDF-Fortran is ok? Should be in lib/pkgconfig/netcdf.pc
and lib/pkgconfig/netcdf-fortran.pc
underneath $NETCDF. Mine are:
$ cat /usr/local/llvm/lib/pkgconfig/netcdf.pc
prefix=/usr/local/llvm
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
ccompiler=mpicc
Name: netcdf-c
Description: NetCDF Client Library for C
URL: http://www.unidata.ucar.edu/netcdf
Version: 4.7.3
Libs: -L${libdir} -lnetcdf
Libs.private: -lpnetcdf -lhdf5_hl -lhdf5 -lm -lz -lcurl
Cflags: -I${includedir}
and
$ cat /usr/local/llvm/lib/pkgconfig/netcdf-fortran.pc
prefix=/usr/local/llvm
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
ccompiler=mpicc
fcompiler=mpif90
Name: netcdf-fortran
Description: NetCDF Client Library for Fortran
URL: http://www.unidata.ucar.edu/netcdf
Version: 4.5.2
Requires.private: netcdf > 4.1.1
Libs: -L${libdir} -lnetcdff
Libs.private: -L${libdir} -lnetcdff -lnetcdf
Cflags: -I${includedir}
Good question! I will check...
Seems to be there:
(base) ed@mikado:~/NCEPLIBS/build$ cat /usr/local/NCEPLIBS-external/lib/pkgconfig/netcdf.pc
prefix=/usr/local/NCEPLIBS-external
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
ccompiler=mpicc
Name: netcdf-c
Description: NetCDF Client Library for C
URL: http://www.unidata.ucar.edu/netcdf
Version: 4.7.4
Libs: -L${libdir} -lnetcdf
Libs.private: -lhdf5_hl -lhdf5 -lm -ldl -lz -lcurl
Cflags: -I${includedir}
(base) ed@mikado:~/NCEPLIBS/build$
(base) ed@mikado:~/NCEPLIBS/build$ cat /usr/local/NCEPLIBS-external/lib/pkgconfig/netcdf-fortran.pc
prefix=/usr/local/NCEPLIBS-external
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
fmoddir=${includedir}
ccompiler=mpicc
fcompiler=mpifort
Name: netcdf-fortran
Description: NetCDF Client Library for Fortran
URL: http://www.unidata.ucar.edu/netcdf
Version: 4.5.3-development
Requires.private: netcdf > 4.1.1
Libs: -L${libdir} -lnetcdff
Libs.private: -L${libdir} -lnetcdff -lnetcdf
Cflags: -I${includedir} -I${fmoddir}
(base) ed@mikado:~/NCEPLIBS/build$
OK, that was a sufficient clue! ;-)
pkg-config was not finding the .pc files because they are not in the path that it normally searches. Instead, they are under the netCDF install. (Is this a bug in the netCDF install?)
So I had to do this:
export PKG_CONFIG_PATH=/usr/local/NCEPLIBS-external/lib/pkgconfig
This causes the build system to find netcdf C and fortran OK, so that's good.
Now I see this:
-- Unable to locate WGRIB2 library and/or Fortran modules
Then it fails like this:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
/home/ed/NCEPLIBS/UFS_UTILS/sorc/chgres_cube.fd/WGRIB2_INCLUDES
used as include directory in directory /home/ed/NCEPLIBS/UFS_UTILS/sorc/chgres_cube.fd
WGRIB2_LIBRARIES (ADVANCED)
linked by target "chgres_cube.exe" in directory /home/ed/NCEPLIBS/UFS_UTILS/sorc/chgres_cube.fd
@climbfuji question for you: when I am specifying something like JPEG_LIBRARIES, do I specify the directory that holds the library? Or do I provide the complete path to the library, including library name?
In other words, do I use:
-DJPEG_LIBRARIES=/usr/lib/x86_64-linux-gnu
or
-DJPEG_LIBRARIES=/usr/lib/x86_64-linux-gnu/libjpeg.so
The better option is to set -DWGRIB2_ROOT=<path>
(or JPEG_ROOT
, etc) where path is the top-level install location (generally contains lib
and include
) and let the find module find the libraries rather than setting the libraries and includes directories manually. It can also be an environment variable instead of passing it to CMake for the same effect.
@edwardhartnett even if you are not using NCEPLIBS-external, the documentation there (how to specify environment variables for packages that you want to compile separately/outside of NCEPLIBS-external) may be helpful? I am wrapped up in meetings all day today, sorry for my slow response.
We don't call find_package_handle_standard_args
in FindWGRIB2.cmake which kind of obfuscates the problem of it not finding the library.
OK, there were some issues with my install of wgrib2. I had to go to NCEPLIBS-external CMakeLists.txt where I found that I have to do make lib
to get the extra libraries, and then looked at the script NCEPLIBS-external/wgrib2/install.sh to see that I should do this:
cp lib/*.mod ${CMAKE_INSTALL_PREFIX}/include
cp lib/libwgrib2.a ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
So now wgrib2 is found!
On to the next issue. I am seeing this message:
ESMFMKFILE not defined. This is the path to esmf.mk file. Without this
filepath, ESMF_FOUND will always be FALSE.
ESMFMKFILE
should point to esmf.mk
(the full path including the file) which is found in lib of wherever ESMF is installed
ESMFMKFILE
should point toesmf.mk
(the full path including the file) which is found in lib of wherever ESMF is installed
The reason for this approach is the directions by ESMF to only use ESMFMKFILE to detect and configure an ESMF installation.
OK, so funny think is that ESMF does not install that file with the files that it does install. However, I set this to the file in the esmf build directory and it found the ESMF libraries.
export ESMFMKFILE=/home/ed/NCEPLIBS-external/esmf/lib/libO/Linux.gfortran.64.mpiuni.default/esmf.mk
Now I am stuck on this:
cmake -DNETCDF=/usr/local/NCEPLIBS-external/ -DJPEG_ROOT=/usr/lib/x86_64-linux-gnu/ -DPNG_PNG_ROOT=/usr/ -DJASPER_ROOT=/usr/local/NCEPLIBS-external/ -DWGRIB2_ROOT=/usr/local/NCEPLIBS-external/ ..
CMake Error at /usr/local/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/local/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
/usr/local/share/cmake-3.17/Modules/FindJasper.cmake:39 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
NCEPLIBS-g2/CMakeLists.txt:23 (find_package)
-- Configuring incomplete, errors occurred!
I'm not sure what is going on. pkg-config is finding jasper.pc:
(base) ed@mikado:~/NCEPLIBS/build$ pkg-config --version jasper
0.29.1
OK, awesome, the build worked for me! How exciting! ;-)
Here's how it worked:
export CC=mpicc
export FC=mpifort
export CXX=mpicxx
export ESMFMKFILE=/home/ed/NCEPLIBS-external/esmf/lib/libO/Linux.gfortran.64.mpiuni.default/esmf.mk
export PKG_CONFIG_PATH=/usr/local/NCEPLIBS-external/lib/pkgconfig
export NETCDF=/usr/local/NCEPLIBS-external/
export JPEG_ROOT=/usr/lib/x86_64-linux-gnu/
export PNG_PNG_ROOT=/usr/
export JASPER_ROOT=/usr/local/NCEPLIBS-external/
export WGRIB2_ROOT=/usr/local/NCEPLIBS-external/
(base) ed@mikado:~/NCEPLIBS/build$ cmake -Wno-dev ..
-- The C compiler identification is GNU 7.5.0
-- The Fortran compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/local/bin/mpicc
-- Check for working C compiler: /usr/local/bin/mpicc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working Fortran compiler: /usr/local/bin/mpifort
-- Check for working Fortran compiler: /usr/local/bin/mpifort - works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/local/bin/mpifort supports Fortran 90
-- Checking whether /usr/local/bin/mpifort supports Fortran 90 - yes
-- Setting build type to 'Release' as none was specified.
-- Found JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (found version "80")
-- Found Jasper: /usr/local/NCEPLIBS-external/lib/libjasper.so (found version "2.0.16")
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11")
-- Found PNG: /usr/lib/x86_64-linux-gnu/libpng.so (found version "1.6.34")
-- Found MPI_Fortran: /usr/local/bin/mpifort (found version "3.1")
-- Found MPI: TRUE (found version "3.1") found components: Fortran
-- Looking for Fortran sgemm
-- Looking for Fortran sgemm - not found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Looking for Fortran sgemm
-- Looking for Fortran sgemm - found
-- Found BLAS: /usr/lib/x86_64-linux-gnu/libblas.so
-- Looking for Fortran cheev
-- Looking for Fortran cheev - not found
-- Looking for Fortran cheev
-- Looking for Fortran cheev - found
-- A library with LAPACK API found.
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'netcdf>=4'
-- Found netcdf, version 4.7.4
-- Checking for module 'netcdf-fortran>=4'
-- Found netcdf-fortran, version 4.5.3-development
-- Found NETCDF_LIBRARIES:
-- Found ESMF library: /home/ed/NCEPLIBS-external/esmf/lib/libO/Linux.gfortran.64.mpiuni.default/libesmf.a
-- Found WGRIB2: include directory /usr/local/NCEPLIBS-external/include, library /usr/local/NCEPLIBS-external/lib/libwgrib2.a
-- Found MPI_C: /usr/local/bin/mpicc (found version "3.1")
-- Found MPI: TRUE (found version "3.1")
-- Creating shell scripts to set environment variables for using NCEPLIBS
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ed/NCEPLIBS/build
Thanks for all the help! I will close this issue.
I have started an issue for netcdf-c about where we install our pkg-config info.
Thanks again!
Thanks for your feedback and for making it work despite all the hiccups along the way. For the next release of the UFS, expect an improved version of NCEPLIBS-external and findNetCDF.cmake
that works without pkg-config
, amongst other things.
I would suggest we coordinate wrt netcdf-c and netcdf-fortran. The newest release of netcdf-c (4.7.4) and the next release of netcdf-fortran includes optional support for szip, and that is something people will be interested in. Unfortunately it complicated the LDFLAGS situation.
When I look at NCEPLIBS master branch I see this in the .gitmodules:
[submodule "netcdf"]
path = netcdf
url = https://github.com/Unidata/netcdf-c
branch = master
You should not be using the master branch. You should be using the last stable release.
It's also not clear why you are build netcdf again here...
I'm not sure if this was before you saw my comment, but we do not build NetCDF again in there. That was before we split out the external libraries into a separate repo a long time ago and this is not what we do.
@kgerheiser thanks for the explanation. ;-)
I am trying to build but there is a failure. It's complaining that NETCDF is not set, but it is set, and the directory it is set to has an include and lib subdirectory with the netCDF include files and libraries.
The NCEPLIBS-external build does not work for me, so the external libraries were installed manually, all into the same directory.