You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The NetCDF_*LIBRARIES variables are strings of linker flags -L<path> -l<lib>.
But target_link_libraries expects full paths to libraries like <path>/lib<lib>.so, otherwise CMake does not know what libraries are effectively being linked.
So even though the build works fine, features like CMAKE_INSTALL_RPATH_USE_LINK_PATH=ON do not work, because <path> is not among the known link directories.
Instead of using nc-config --libs, you could use pkg-config, for which CMake has builtin support:
In particular pkg_search_module would then give you *_LIBRARIES which is a list of full paths, which can be used in target_link_libraries, so that CMAKE_INSTALL_RPATH_USE_LINK_PATH=ON works again.
The text was updated successfully, but these errors were encountered:
The "correct" way (simply because it is the widely accepted standard across the NWP community) to find and link to netCDF is by (a) updating findNetcdf.cmake to this version https://github.com/NOAA-EMC/CMakeModules/blob/develop/Modules/FindNetCDF.cmake or the ECMWF one (these two versions are nearly the same, and functionally identical). Then, one can simply do (example from Unified Forecast System/CCPP):
find_package(NetCDF 4.7.4 REQUIRED C Fortran)
...
target_link_libraries(myproject PUBLIC NetCDF::NetCDF_Fortran NetCDF::NetCDF_C)
and that takes care of the include and linker flags. And, as an aside, this works with spack.
In
cprnc/CMakeLists.txt
Lines 86 to 87 in fec7c42
The
NetCDF_*LIBRARIES
variables are strings of linker flags-L<path> -l<lib>
.But
target_link_libraries
expects full paths to libraries like<path>/lib<lib>.so
, otherwise CMake does not know what libraries are effectively being linked.So even though the build works fine, features like
CMAKE_INSTALL_RPATH_USE_LINK_PATH=ON
do not work, because<path>
is not among the known link directories.Instead of using
nc-config --libs
, you could use pkg-config, for which CMake has builtin support:https://cmake.org/cmake/help/latest/module/FindPkgConfig.html
In particular
pkg_search_module
would then give you*_LIBRARIES
which is a list of full paths, which can be used intarget_link_libraries
, so thatCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON
works again.The text was updated successfully, but these errors were encountered: