Unidata / netcdf-cxx4

Official GitHub repository for netCDF-C++ libraries and utilities.
Other
124 stars 49 forks source link

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

Open peter-hristov opened 3 years ago

peter-hristov commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 1 month ago

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 #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: https://github.com/Unidata/netcdf-cxx4/blob/84ddbe37be501887c5bb5fca889dbbb56add4909/CMakeLists.txt#L633