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

FindNetCDF finds libnetcdf but not netcdf.mod #21

Open
rouson opened this issue Jun 13, 2017 · 3 comments
Open

FindNetCDF finds libnetcdf but not netcdf.mod #21

rouson opened this issue Jun 13, 2017 · 3 comments

Comments

@rouson
Copy link

rouson commented Jun 13, 2017

Pleas let me know if you can offer any advice on resolving the following problem:

I set up a small repository to learn how to use FindNetCDF. The repository has just two Fortran source files, only one of which depends on NetCDF as specified in a single use netcdf statement. An abbreviated transcript of my results using my repository's add-cmake-file branch follows:

$ git clone --recursive https://github.com/sourceryinstitute/learning-cmake-find.git
$ cd learning-cmake-find
$ git checkout add-cmake-file
$ mkdir build
$ cd build 
$ FC=gfortran cmake ..

-- Found NetCDF: /opt/local/lib/libnetcdf.dylib

$ make
Scanning dependencies of target io_routines
[ 50%] Building Fortran object
CMakeFiles/io_routines.dir/src/io_routines.f90.o
/Users/rouson/Code/learning-make-find/src/io_routines.f90:18:8:

     use netcdf
        1
Fatal Error: Can't open module file ‘netcdf.mod’ for reading at (1): No
such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/io_routines.dir/src/io_routines.f90.o] Error 1
make[1]: *** [CMakeFiles/io_routines.dir/all] Error 2
make: *** [all] Error 2

I used MacPorts on macOS Sierra to install netcdf and netcdf-fortran with the resulting installed files:

$ port contents netcdf
Port netcdf contains:
  /opt/local/bin/nc-config
  /opt/local/bin/nccopy
  /opt/local/bin/ncdump
  /opt/local/bin/ncgen
  /opt/local/bin/ncgen3
  /opt/local/include/netcdf.h
  /opt/local/include/netcdf_mem.h
  /opt/local/include/netcdf_meta.h
  /opt/local/lib/cmake/netCDF/netCDFConfig.cmake
  /opt/local/lib/cmake/netCDF/netCDFConfigVersion.cmake
  /opt/local/lib/cmake/netCDF/netCDFTargets-release.cmake
  /opt/local/lib/cmake/netCDF/netCDFTargets.cmake
  /opt/local/lib/libnetcdf.11.3.0.dylib
  /opt/local/lib/libnetcdf.11.dylib
  /opt/local/lib/libnetcdf.dylib
  /opt/local/lib/libnetcdf.settings
  /opt/local/lib/pkgconfig/netcdf.pc
  /opt/local/share/man/man1/nccopy.1.gz
  /opt/local/share/man/man1/ncdump.1.gz
  /opt/local/share/man/man1/ncgen.1.gz
  /opt/local/share/man/man1/ncgen3.1.gz
  /opt/local/share/man/man3/netcdf.3.gz

$ port contents netcdf-fortran
Port netcdf-fortran contains:
  /opt/local/bin/nf-config
  /opt/local/include/netcdf.inc
  /opt/local/include/netcdf.mod
  /opt/local/include/netcdf4_f03.mod
  /opt/local/include/netcdf4_nc_interfaces.mod
  /opt/local/include/netcdf4_nf_interfaces.mod
  /opt/local/include/netcdf_f03.mod
  /opt/local/include/netcdf_fortv2_c_interfaces.mod
  /opt/local/include/netcdf_nc_data.mod
  /opt/local/include/netcdf_nc_interfaces.mod
  /opt/local/include/netcdf_nf_data.mod
  /opt/local/include/netcdf_nf_interfaces.mod
  /opt/local/include/typesizes.mod
  /opt/local/lib/libnetcdff.6.dylib
  /opt/local/lib/libnetcdff.a
  /opt/local/lib/libnetcdff.dylib
  /opt/local/lib/pkgconfig/netcdf-fortran.pc
  /opt/local/share/man/man3/netcdf_fortran.3.gz
@jedbrown
Copy link
Owner

jedbrown commented Jun 13, 2017 via email

@rouson
Copy link
Author

rouson commented Jun 13, 2017

Thanks for the quick reply. I'll let you know once it's sorted out. If I don't sort it out on my own, I'll ask for help from Kitware, Inc., on CMake.

@zbeekman
Copy link

Hi Damian,

You need to add the NetCDF includes:

cmake_minimum_required(VERSION 3.7)

project(build_against_netcdf LANGUAGES Fortran)

# Find the native NetCDF includes and library
include(cmake-modules/FindNetCDF.cmake)

set (NETCDF_F90 "YES") # Require Fortran interfaces to be FOUND
find_package (NetCDF REQUIRED)

include_directories(${NETCDF_INCLUDES})

add_library(io_routines src/io_routines.f90)

target_link_libraries (io_routines ${NETCDF_LIBRARIES})

A really good way to see what facilities a find module provides is to run ccmake or cmake-gui and then toggle the advanced options. In ccmake t toggles the advanced options. Ctrl-n is go to the next line, Ctrl-p is go to the previous line, c is configure (i.e. run cmake), g is configure, generate and quit:

asciicast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants