Building GMT. CMake warning. Conflict with Anaconda3?

Intro

I try to build GMT from scratch (as indicated here) on Ubuntu 20.04.

Warning

When I run cmake .. I got this message (I copy the final of it):

...
*  GMT_DOCDIR                 : /usr/local/share/doc
*  GMT_MANDIR                 : /usr/local/share/man
-- Configuring done
CMake Warning at src/CMakeLists.txt:510 (add_library):
  Cannot generate a safe runtime search path for target gmtlib because files
  in some directories may conflict with libraries in implicit directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/federico/anaconda3/lib

  Some of these libraries may not be found correctly.


CMake Warning at src/CMakeLists.txt:770 (add_library):
  Cannot generate a safe runtime search path for target supplements because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/federico/anaconda3/lib

  Some of these libraries may not be found correctly.


CMake Warning at src/CMakeLists.txt:561 (add_executable):
  Cannot generate a safe runtime search path for target gmt because files in
  some directories may conflict with libraries in implicit directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/federico/anaconda3/lib

  Some of these libraries may not be found correctly.


-- Generating done
-- Build files have been written to: /home/federico/Software/gmt/build

Error:

Then, when I run cmake --build . --target install I get an error.

...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/libgdal.so: referencia a `TIFFReadScanline@LIBTIFF_4.0' sin definir
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/libgdal.so: referencia a `TIFFNumberOfTiles@LIBTIFF_4.0' sin definir
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/gmt.dir/build.make:96: src/gmt] Error 1
make[1]: *** [CMakeFiles/Makefile2:833: src/CMakeFiles/gmt.dir/all] Error 2
make: *** [Makefile:152: all] Error 2

That’s because your system have two copies of some library (e.g., libz.so), one from Anaconda and another one from the system.

I don’t have a final solution, but there are two workarounds:

  1. You can temporarily uncomment conda init settings from shell init script, restart a terminal, and build GMT again. Before building GMT, remember to remove the old build directory completely. After building GMT, you need to restore the conda init settings.

  2. You can specify the path to look for the libraries in your ConfigUser.cmake file. The folllowing works well for me on macOS. I think changing /usr/local to /usr/lib or /usr/lib/x86_64-linux-gnu for work for you.

set (GDAL_ROOT "/usr/local/")
set (GEOS_ROOT "/usr/local/")
set (PCRE_ROOT "/usr/local/")
set (NETCDF_ROOT "/usr/local/")

@seisman and @Esteban82 kindly, did you find a solution for this issue? I am using Ubuntu 22.04, and getting the same error when building GMT 6.4 from source. Here is part of the output I am getting:

CMake Warning at src/CMakeLists.txt:510 (add_library):
Cannot generate a safe runtime search path for target gmtlib because files
in some directories may conflict with libraries in implicit directories:

runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
  /home/robin/anaconda3/lib

Some of these libraries may not be found correctly.

CMake Warning at src/CMakeLists.txt:561 (add_executable):
Cannot generate a safe runtime search path for target gmt because files in
some directories may conflict with libraries in implicit directories:

runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
  /home/robin/anaconda3/lib

Some of these libraries may not be found correctly.

CMake Warning at src/CMakeLists.txt:770 (add_library):
Cannot generate a safe runtime search path for target supplements because
files in some directories may conflict with libraries in implicit
directories:

runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
  /home/robin/anaconda3/lib

Some of these libraries may not be found correctly.

@pwessel and team, kindly help …

Well, you have an advice in the post before yours. Did you try it?

Yes I tried that, still does not work **** After upgrading to Ubuntu 22.10, I was able to install from source seamlessly. The upgrade may have resolved the references to Anaconda3. Thank you

I am neither using conda nor Linux so have nothing to add beyond what was stated t

If you move anaconda out of the path (how, I don’t know since I don’t use too and I’m a Win guy), the problem will disappear for sure.