[cmake-developers] [CMake 0015132]: find_library retrieves libraries from $PATH even when they can be found in the proper locations.

Mantis Bug Tracker mantis at public.kitware.com
Sat Sep 6 15:26:04 EDT 2014


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=15132 
====================================================================== 
Reported By:                Greg Jung
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15132
Category:                   CMake
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2014-09-06 15:26 EDT
Last Modified:              2014-09-06 15:26 EDT
====================================================================== 
Summary:                    find_library retrieves libraries from $PATH even
when they can be found in the proper locations.
Description: 
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


Steps to Reproduce: 
put an acceptable library file in your %PATH%, run cmake:
SET(CMAKE_PREFIX_PATH "c:/proper/lib")
find_library(WRONG libname)



Additional Information: 
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.
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2014-09-06 15:26 Greg Jung      New Issue                                    
2014-09-06 15:26 Greg Jung      File Added: cmakebug                         
======================================================================



More information about the cmake-developers mailing list