'Anaconda confuses C/C++ linker with duplicate libraries

This is happening on a Linux system. Anaconda comes with several C libraries, like libz, or libgomp. I have most of these libraries also installed globally on my system in /usr/lib. Now, whenever the linker or the CMake find_package looks for these libraries, I might end up with conflicting versions:

Readline_INCLUDE_DIR:PATH=/home/mattmilten/anaconda3/include
Readline_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libreadline.so

This usually breaks my build.

How can I give my system libraries precedence over the anaconda ones? My LD_LIBRARY_PATH is empty by the way.



Solution 1:[1]

Have you set environment variables like C_INCLUDE_PATH to your anaconda include dir? This will add that path to your header search path but not library search path (which is LIBRARY_PATH). If so you can unset C_INCLUDE_PATH before using cmake. Or you can prepend your global library path to C_INCLUDE_PATH if you do want to link against some anaconda libraries you do not have in globle library path.

Solution 2:[2]

I usually rename my acondada directoy and rerun ccmake .. from the build directory. I check all entries in the ccmake (not cmake) then configure. Then to reactivate python I change the name back to match my path exports.

Solution 3:[3]

Anaconda places itself at the front of your PATH environment variable, so cmake can end up looking there first for the libraries. You can comment out the startup script for anaconda from your ~/.bashrc or ~/.bash_profile so that Anaconda will be absent from path when you try to build.

If you already ran ./configure, remember to remove the CMakeCache.txt file in the build directory.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jason Zang
Solution 2 John Coke
Solution 3 pmt-neuro