Search code examples
linuxcondanetcdfnetcdf4nco

ncap2: error while loading shared libraries: libnetcdf.so.7: cannot open shared object file: No such file or directory


I tried to install nco in a remote server (RHEL 7.8) and I am not the root which means I can't use the sudo or yum in the terminal. Then I followed the instructions on the main page on nco (http://nco.sourceforge.net/src/) in which it is said pre-built way is recommended. So I used conda method. But when I used conda install -c conda-forge nco, the speed is too low. And finally I was told solving the environment is not successful. After that I searched the nco in conda, in https://anaconda.org/conda-forge/nco I was told that conda install -c conda-forge/label/broken nco would be ok. Yes the installation is completed. But when I want to use the command ncap2, I was told that

ncap2: error while loading shared libraries: libnetcdf.so.7: cannot open shared object file: No such file or directory

I checked my LD_LIBRARY_PATH, but I couldn't find the link towards libnetcdf.so.7. I used find command in order to find where the libnetcdf.so.7 is, but as you know I was operating on a server, so most access is denied. Here is my ~/.bashrc:

export PATH="/home/xushan/anaconda3/bin:$PATH"
export PATH="$PATH:/home/xushan/openmpi/bin"
#export PATH= "$HOME/openmpi/bin:$PATH"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/xushan/openmpi/lib"
export VER_MPI="NOMPI"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/xushan/SURFEX_v8_1_public/open_SURFEX_V8_1/src/LIB"
#export VER_USER="FORC"
export PATH="/home/xushan/anaconda3/bin/ncdump:$PATH"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/xushan/anaconda3/lib"

One thing it is weird is that when I ls to /usr/local/lib, there is nothing.... So is there any way to help me to complete the installation? I tried the following commands suggested in http://nco.sourceforge.net/src/:

wget https://github.com/nco/nco/archive/4.9.4.tar.gz
tar xvzf 4.9.4.tar.gz
cd nco-4.9.4
./configure --prefix=/usr/local
make
sudo make install
export PATH=/usr/local/bin\:${PATH}
export LD_LIBRARY_PATH=/usr/local/lib\:${LD_LIBRARY_PATH}

but when I run ./configure --prefix=/usr/local, I was told that

checking for /opt/local/include/netcdf.h... no
checking for /opt/local/lib/libnetcdf.a... no
checking netcdf.h usability... no
checking netcdf.h presence... no
checking for netcdf.h... no
configure: error: in `/home/xushan/nco-4.6.3':
configure: error: cannot find netCDF header
See `config.log' for more details

So is there anyone who can help me? thanks a lot! (Question is that I cannot find where the libnetcdf.so.7 is......I am a beginner for compiling something on remote server....especially soda and yum are banned for common users....)


Solution

  • You can create a new conda environment for nco. It's possible that its dependencies clash with some programs in your current environment.

    conda create -n myenv -c conda-forge python=3 nco
    conda activate myenv
    ncap2
    

    Update 20200914: In response to followup comments below, please understand that Conda is just a nice installer for NCO, and ensures that you have all the dependencies and libraries in one place. So long as the Conda bin and lib dirs come first in your paths, Conda-installed NCO works well, whether within or without a Bash script.