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

Issue with using a local build of netcdf-c and netcdf-c++ #95

Open
peter-hristov opened this issue Aug 23, 2020 · 6 comments
Open

Issue with using a local build of netcdf-c and netcdf-c++ #95

peter-hristov opened this issue Aug 23, 2020 · 6 comments

Comments

@peter-hristov
Copy link

I'm running Ubuntu 20, netcdf-c 4.7.4 and the "working" branch of netcdf-cxx.

I'm compiling netcdf with

cmake -D CMAKE_INSTALL_PREFIX=~/Projects/libraries/netcdf-c/install

I'm compiling netcdf-cxx with the command:

cmake -D CMAKE_PREFIX_PATH=~/Projects/libraries/netcdf-c/install -D CMAKE_INSTALL_PREFIX=~/Projects/libraries/netcdf-cxx/install ..

In my own application where I would like to use those two librarires I'm compiling with

cmake -D CMAKE_PREFIX_PATH="~/Projects/libraries/netcdf-c/install;~/Projects/libraries/netcdf-cxx/install" ..

In my cmake file the netcdf related things are

find_package(netCDF REQUIRED)

and

target_link_libraries(${PROJECT_NAME}
    netcdf
    netcdf_c++4
    )

Both netcdf-c and netcdf-xx compile and install fine, but when I try to build my application with make I get the following error message: "/usr/local/include/netcdf:5:10: fatal error: netcdf.h: No such file or directory"

I'm not sure why it's not finding the netcdf-cxx header files. Furthermore when I try to use "find_package(netCDFCxx REQUIRED)
" i get the cmake error "Could not find a package configuration file provided by "netCDFCxx" with any of the following names:`

Do you have any idea where I may be going wrong? Please let me know if I can provide any additional information.

@WardF
Copy link
Member

WardF commented Aug 27, 2020

I'll take a look at this but I'm curious if the file /usr/local/include/netcdf.h exists on your system? If so, this indicates that there is another system-level netCDF-C install on your system, which may be muddying the waters.

@aosterthun
Copy link

Regarding the find_package(netCDFCxx REQUIRED) call, the netCDFCxxConfig.cmake is installed into the same directory as the netcdf-c library. I had to use: cmake .. -DnetCDFCxx_DIR=~/lib/cmake/netCDF/ for you it should be something like: cmake .. -DnetCDFCxx_DIR=~/Projects/libraries/netcdf-cxx/install/lib/cmake/netCDF/. Maybe there is a way where you can just set CMAKE_PREFIX_PATH but I haven't found it yet.

@peter-hristov
Copy link
Author

Hi,

Thanks for the comments. @WardF there was a leftover file /usr/local/include/netcdf.h and I've removed it along with any other netcdf related files in /usr.

@aosterthun I tried that, but there's no netCDFCxxConfig.cmake file in my install folder, there's only a netCDFCxxConfigVersion.cmake file. Here's the installed filed for both netcdf and netcdf-cxx4

Screenshot from 2020-09-16 08-42-15

Screenshot from 2020-09-16 08-45-32

@aosterthun
Copy link

For one it is weird that that .cmake file is missing.
Besides that the print our you posted shows that you have installed netcdf-cxx4 into both ~/Projects/libraries/netcdf-cxx/install and ~/Projects/libraries/netcdf-cxx4/install. I guess that is not what you intended to do.

As you can see in #97 I'm currently also working on getting a project based installation of netcdf-cxx4 to work. I would be interesting to see your build steps. I figure you are using autotools to build netcdf-cxx4 and it's dependencies, since at least for me a full cmake build pipeline did not work.

@hasegawa-yuta-jaea
Copy link

Hi,

I watched the same issue. I found there might be two causes:

  1. When netCDFCxxConfig.cmake was missing, one might compile netcdf-cxx4 of v4.3.1 or older versions. The issue was already fixed (see CMake Config files missing on install. #43), but not released yet.

  2. After solving 1, however, find_package did not work. This is because netCDFCxxConfig.cmake was installed in lib/cmake/netCDF, not lib/cmake/netCDFCxx. What a confusing! Please consider fixing following line:

    set(ConfigPackageLocation "${CMAKE_INSTALL_LIBDIR}/cmake/netCDF")

@janfer95
Copy link

janfer95 commented Dec 3, 2024

Is there any official recommendation on how to correctly use find_package in this case? As @hasegawa-yuta-jaea mentioned, when using find_package(netCDFCxx REQUIRED) in another project, Cmake is not able to locate the package, unless I rename lib/cmake/netCDF to lib/cmake/netCDFCxx.

Maybe there's a Cmake command that I'm missing?
In my Cmake file I link the library like the following:

find_package(netcdfCxx REQUIRED)
# ... Other configurations
target_link_libraries(${EXECUTABLE_NAME} netCDF::netcdf-cxx4 netCDF::netcdf)

Also, thank you a lot for this C++ library!

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

5 participants