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

NetCDF Library Linkage on Windows Using CMake #2533

Open
kmkim3182 opened this issue Oct 21, 2022 · 4 comments
Open

NetCDF Library Linkage on Windows Using CMake #2533

kmkim3182 opened this issue Oct 21, 2022 · 4 comments

Comments

@kmkim3182
Copy link

NetCDF Version: netCDF-C 4.9.0 (2022-06-10, the latest for now)
IDE: Visual Studio 2022
CMake Version: 3.24.1
Compiler: MSVC++ and nvcc

Hello.

I'm not sure it is proper to upload my question here, so please tell me where to ask if the question is not related to here.

My issue is configuring and compiling a program which involves NetCDF as a third-party library.
CMake itself does not generate a problem, but building the program has a issue. ("cmake --build ." or MSVC builder)
The error message from the linker says it cannot open the input library files:

  • hdf5-shared
  • hdf5_hl-shared
  • C:/share/VS15/x64/lib/zlib.lib
  • C:/share/VS15/x64/lib/libcurl_imp.lib

For flexible compilation, I'm using CMake, but NetCDF does not provide "FindNetCDF.cmake" for "find_package(NetCDF)" command in CMake.
Therefore, I googled and found a custom "FindNetCDF.cmake" from VTK:

https://gitlab.kitware.com/vtk/vtk/-/blob/master/CMake/FindNetCDF.cmake

and used this as:

target_link_libraries(my_project INTERFACE NetCDF::NetCDF)

In the FindNetCDF script, it calls find_package(netCDF CONFIG QUIET), and I assumed this instruction invokes the script provided by the NetCDF team, "C:\Program Files\netCDF 4.9.0\lib\cmake\netCDF\netCDFConfig.cmake"
And in the "netCDFConfig.cmake" file, it includes "netCDFTargets.cmake" which is located at the same directory.
The problem is here, which lies at line 56 and says:

set_target_properties(netCDF::netcdf PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${_IMPORT_PREFIX}/include" INTERFACE_LINK_LIBRARIES "hdf5-shared;hdf5_hl-shared;C:/share/VS15/x64/lib/zlib.lib;C:/share/VS15/x64/lib/libcurl_imp.lib" )

When I build the project, the four libraries written after "INTERFACE_LINK_LIBRARIES" cause the linker error.
Those libraries literally do not exist.

So, my question is, is there any alternative to still utilize CMake's find_package feature in linking my project to NetCDF?
Since I pursue cross-compile feature, I want to use CMake for my project.

Thanks in advance.
Screenshot_1

@DennisHeimbigner
Copy link
Collaborator

DennisHeimbigner commented Oct 21, 2022 via email

@kmkim3182
Copy link
Author

Dear @DennisHeimbigner

I exactly followed what you said.
I downloaded a binary this one https://downloads.unidata.ucar.edu/netcdf-c/4.9.0/netCDF4.9.0-NC4-DAP-64.exe
and found what I posted above.
I think it's an internal problem.

@DennisHeimbigner
Copy link
Collaborator

I am not an expert in cmake, so I will have to turn this over to someone
more knowledgeable. Perhaps you should post this question
to the netcdf mailing list?

@kmkim3182
Copy link
Author

Thanks for your support.

I have not posted anything to the mailing list.
It is right to mail this to netcdfgroup@unidata.ucar.edu?

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

2 participants