MantisBT - CMake
View Issue Details
0015132CMakeCMakepublic2014-09-06 15:262016-06-10 14:31
Greg Jung 
Kitware Robot 
normalminoralways
closedmoved 
Mingw/Msys CygWin64 Win7Windows 7 64-bit6.1
CMake 3.0.1 
 
0015132: find_library retrieves libraries from $PATH even when they can be found in the proper locations.
Contrary to documentation, find_library usurps my intention when it
has an apparent match from $ENV{PATH}.

This also occurs if I specify the preference explicitly via
CMAKE_PREFIX_PATH: if the library is found in program path, it picks those up
for linkage instead of the specified preference.
In the folowing example, I happen to have only one of the libraries fftw3, fftw3f in my /local32/lib. So the FFTWDIR is set to pick up libraries as in FindFFTW.cmake:
CMakeLists.txt:
    set(CMAKE_PREFIX_PATH ${FFTWDIR})
    find_package(FFTW QUIET)
FindFFTW.cmake:

find_library(FFTW_LIBRARY NAMES fftw3)
message(STATUS " FFTW_LIBRARY: ${FFTW_LIBRARY}")
find_library(FFTWF_LIBRARY NAMES fftw3f)
message(STATUS " FFTWF_LIBRARY: ${FFTWF_LIBRARY}")
set(FFTW_LIBRARIES ${FFTW_LIBRARY} ${FFTWF_LIBRARY})
find_path(FFTW_INCLUDE_DIR NAMES fftw3.h)

result: CMakeCache.txt

//GDL: Specifiy the FFTW directory tree
FFTWDIR:PATH=D:/programs/win32libs

//Path to a library.
FFTWF_LIBRARY:FILEPATH=D:/programs/win32libs/lib/libfftw3f.a

//Path to a file.
FFTW_INCLUDE_DIR:PATH=E:/mingw/local32/include

//Path to a library.
FFTW_LIBRARY:FILEPATH=E:/mingw/local32/lib/libfftw3.a
put an acceptable library file in your %PATH%, run cmake:
SET(CMAKE_PREFIX_PATH "c:/proper/lib")
find_library(WRONG libname)

In cygwin, I set LDFLAGS="-L/opt/local/lib -L/usr/local/lib" which are
ingested, with my modified Platform/UnixPaths.cmake, into
CMAKE_SYSTEM_LIBRARY_PATH and into CMAKE_SYSTEM_INCLUDE_PATH.


 <Platform/UnixPaths> inspecting LDFLAGS: -L/opt/local/lib -L/usr/local/lib
<Platform/UnixPaths> adding system library path: /opt/local/lib
<Platform/UnixPaths> adding system library path: /usr/local/lib
so according to the docs, CMAKE_SYSTEM_LIBRARY_PATH and CMAKE_SYSTEM_INCLUDE_PATH
will be utilized in find_library and in find_path, respectively. Instead I get
Junk from the mingw side bleeding into it because I have an application directory in %PATH%:


PLPLOT_LIBRARY: /cygdrive/d/programs/libplplotd.dll.a
FindPlplot> PLPLOT_LIBRARY_DIR: /cygdrive/d/programs
PLPLOT_INCLUDE=? /cygdrive/d/programs/../include
Found PLPLOT: /cygdrive/d/programs/libplplotd.dll.a;/cygdrive/d/programs/libplplotcxxd.dll.a
 (errors due to bad linkage)
Looking for c_plslabelfunc in /cygdrive/d/programs/libplplotd.dll.a;/cygdrive/d/programs/libplplotcxxd.dll.a
Looking for c_plslabelfunc in /cygdrive/d/programs/libplplotd.dll.a;/cygdrive/d/programs/libplplotcxxd.dll.a - not found

Of course, I reset my $PATH for the cygwin to run right, but the find_library behavior is wrong.
No tags attached.
? cmakebug (4,078) 2014-09-06 15:26
https://public.kitware.com/Bug/file/5245/cmakebug
Issue History
2014-09-06 15:26Greg JungNew Issue
2014-09-06 15:26Greg JungFile Added: cmakebug
2014-09-08 08:57Brad KingNote Added: 0036741
2016-06-10 14:29Kitware RobotNote Added: 0042622
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0036741)
Brad King   
2014-09-08 08:57   
The documentation of find_library:

 http://www.cmake.org/cmake/help/v3.0/command/find_library.html [^]

says that ENV{PATH} is step 4, while CMAKE_SYSTEM_LIBRARY_PATH is step 5, so of course entries in PATH come before the builtin search paths. I do not see from the provided information why setting CMAKE_PREFIX_PATH does not work, but please also try setting CMAKE_LIBRARY_PATH and CMAKE_INCLUDE_PATH.
(0042622)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.