https://github.com/cwsmith/cmakenetcdfpkgconfig
Demonstrates linking problem using Cmake PkgConfig for NetCDF and NetCDF-CXX4
https://github.com/cwsmith/cmakenetcdfpkgconfig
Last synced: 10 days ago
JSON representation
Demonstrates linking problem using Cmake PkgConfig for NetCDF and NetCDF-CXX4
- Host: GitHub
- URL: https://github.com/cwsmith/cmakenetcdfpkgconfig
- Owner: cwsmith
- License: mit
- Created: 2020-04-14T12:10:10.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-14T12:53:38.000Z (about 6 years ago)
- Last Synced: 2025-03-01T00:39:14.453Z (over 1 year ago)
- Language: C++
- Size: 6.84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cmakeNetcdfPkgConfig
Demonstrates linking problem using CMake PkgConfig `pkg_check_modules` to import NetCDF
and NetCDF-CXX4 targets when using the wrong `cmake_minimum_version`.
Using `cmake_minimum_version(VERSION 3.00.0)` and imported targets from
PkgConfig via
`target_link_libraries(foo PkgConfig::NetCDF PkgConfig::NetCDF-CXX4)`
results in the following linking error:
```
$ make
Scanning dependencies of target foo
[ 50%] Building CXX object CMakeFiles/foo.dir/foo.cpp.o
[100%] Linking CXX executable foo
/gpfs/u/software/dcs-spack-install/v0133gccSpectrum/linux-rhel7-power9le/gcc-7.4.0-1/netcdf-cxx4-4.3.1-7lwefeghu3za7l46xhlezrgdrhgrddq4/lib/libnetcdf_c++4.so:
undefined reference to `nc_inq_var_filter'
/gpfs/u/software/dcs-spack-install/v0133gccSpectrum/linux-rhel7-power9le/gcc-7.4.0-1/netcdf-cxx4-4.3.1-7lwefeghu3za7l46xhlezrgdrhgrddq4/lib/libnetcdf_c++4.so:
undefined reference to `nc_def_var_filter'
collect2: error: ld returned 1 exit status
make[2]: *** [foo] Error 1
make[1]: *** [CMakeFiles/foo.dir/all] Error 2
```
Using `cmake_minimum_version(VERSION 3.13.0)` will result in successful
linking.
## contents
- CMakeLists.txt: build file
- foo.cpp: netcdfcxx source code
- LICENSE: legal stuff
- README.md: this file
- netcdfPkgConfig: directory with netcdf pkgconfig files
- netcdf-cxx4.pc
- netcdf.pc
## setup
Use spack to install netcdf and netcdf-cxx4.
```
git clone https://github.com/spack/spack.git
cd spack
git checkout v0.13.3
export SPACK_ROOT=$PWD/spack/
export PATH=$SPACK_ROOT/bin:$PATH
source $SPACK_ROOT/share/spack/setup-env.sh
#setup compilers and packages if needed
spack install netcdf-cxx4@4.3.1 ^netcdf@4.7.2+parallel-netcdf ^hdf5+hl+cxx
```
This will create the pkgconfig files located in the `netcdfPkgConfig` directory.
## build the example package
```
ncDir=`spack location -i netcdf@4.7.2`
ncxxDir=`spack location -i netcdf-cxx4@4.3.1`
export PKG_CONFIG_PATH=\
$PKG_CONFIG_PATH:\
${ncDir}/lib/pkgconfig:\
${ncxxDir}/lib/pkgconfig
# setup compiler (i.e., module load ...)
git clone https://github.com/cwsmith/cmakeNetcdfPkgConfig.git
mkdir build-cmakeNetcdfPkgConfig
cd !$
cmake ../cmakeNetcdfPkgConfig
make
```