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

Cmake FindNetCDF reports conflicting library when anaconda/conda is installed #53

Open
jamal919 opened this issue Feb 2, 2022 · 6 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@jamal919
Copy link
Member

jamal919 commented Feb 2, 2022

Hi all,

I was trying to build SCHISM with cmake build system in a new Ubuntu machine (Ubuntu 20.04.3 LTS). I have installed necessary packages through apt - compilers, netcdf (c and fortran), mpich, cmake etc. I have also anaconda installed on my computer in home directory ~/.anaconda3.

If I issue the cmake configure command cmake -C ../cmake/SCHISM.local.build -C ../cmake/SCHISM.local.ubuntu ../src -DUSE_WWM=on, the output has something weird - it picks up the fortran netcdf fine, but links to the netcdf-c library inside ~/.anaconda

-- FindNetCDF defines targets:
--   - NetCDF_VERSION [4.7.3]
--   - NetCDF_PARALLEL [FALSE]
--   - NetCDF_C_CONFIG_EXECUTABLE [/usr/bin/nc-config]
--   - NetCDF::NetCDF_C [SHARED] [Root: /usr] Lib: /home/khan/.anaconda3/lib/libnetcdf.so
--   - NetCDF_Fortran_CONFIG_EXECUTABLE [/usr/bin/nf-config]
--   - NetCDF::NetCDF_Fortran [SHARED] [Root: /usr] Lib: /usr/lib/x86_64-linux-gnu/libnetcdff.so

...

### Configuring Utilities
-- In /Utility NetCDF_LIBS /home/khan/.anaconda3/lib/libnetcdf.so;/usr/lib/x86_64-linux-gnu/libnetcdff.so
-- In /Utility NetCDF_LIBS /home/khan/.anaconda3/lib/libnetcdf.so;/usr/lib/x86_64-linux-gnu/libnetcdff.so

Then afterwards, if I build schism, the executables are created fine! But they fail during execution - whenever NetCDF is involved.

My experience with cmake is rather short. I tried passing the NetCDF_ROOT variable to FindNetCDF.cmake through -DNetCDF_ROOT flag, but no avail.

Any fix for this issue? (Other than, of course, editing CMakeCache.txt by hand).

Thanks.

Edit: The problem is reproduced in multiple machines with different software configurations, but with existence of anaconda in home directory.

@jamal919
Copy link
Member Author

jamal919 commented Feb 3, 2022

For now, I am avoiding such mismatch by explicitly defining NetCDF_C environment variable, either by

  1. bash export export NetCDF_C=/usr/lib/x86_64-linux-gnu/
  2. cmake flag cmake -C ../cmake/SCHISM.local.build -C ../cmake/SCHISM.local.ubuntu ../src -DNetCDF_C=/usr/lib/x86_64-linux-gnu/

Thanks.

@platipodium
Copy link
Member

Dear Jamal, thanks for reporting this. I am not an export in CMake either but I have encountered problems with multiple netcdf libs installed system-wide and through conda persistently. So thank you for your fix.

You may also move the -DNetCDF_C=/usr/lib/x86_64-linux-gnu/ into a CMake.local definition file for your system in the cmake subdirectory

@platipodium platipodium added bug Something isn't working help wanted Extra attention is needed labels Feb 17, 2022
@platipodium
Copy link
Member

Here's the CMakeCache.txt from my system with macports and anaconda installed. Same problem

//NetCDF nc-config helper
NetCDF_C_CONFIG_EXECUTABLE:FILEPATH=/opt/local/bin/nc-config

//NetCDF C include directory
NetCDF_C_INCLUDE_FILE:FILEPATH=/opt/local/include/netcdf.h

//NetCDF C library
NetCDF_C_LIBRARY:STRING=/opt/homebrew/anaconda3/lib/libnetcdf.dylib

So the nc-config and --includedir are correctly assigned, but the library is taken from anaconda; also the same for the Fortran part.

Setting -DNetCDF_C did not remedy this.

@jamal919
Copy link
Member Author

Hi Carsten,

Have you tried a fresh build directory. I remember that the first time I was trying I already had CMakeCache.txt with old values and setting -DNetCDF_C did not help. Then after cleaning the build directory (rm -rf) the values were properly set. Could be a solution for you.

I have no experience with mac system, and no way to reproduce this behaviour either in similar environment.

@jamal919
Copy link
Member Author

jamal919 commented Mar 3, 2022

Hi Carsten @platipodium,

Did you finally found a way to make the cmake to pick up NetCDF correctly? I am just curious based on your recent commit ebb27b6

@platipodium
Copy link
Member

Works for me, but only after removing conda from my PATH (despite the hints given in the cmake config files)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants