[CMake] Find Library would not find the library

Andreas Pakulat apaku at gmx.de
Wed Mar 9 18:25:52 EST 2011


On 09.03.11 21:36:25, Ankur Handa wrote:
> I'm using find_library to find a library in a given directory but it has
> many different versions of this library listed as libcxcore.so,
> libcxcore.so.2.1 and libcxcore.so.2.1.0  I wrote a very simple cmake file
> 
> cmake_minimum_required(VERSION 2.8)
> 
> find_library(OpenCV_LIBRARY_RELEASE NAMES "cxcore" PATHS
> "/homes/ahanda/openCV2.1/OpenCV-2.1.0/opencvinstall/lib" NO_DEFAULT_PATH)
> 
> if ( OpenCV_LIBRARY_RELEASE)
>         message("LIBRARY FOUND = " ${OpenCV_LIBRARY_RELEASE})
> endif()
> 
> if ( NOT OpenCV_LIBRARY_RELEASE)
>         message("LIBRARY NOT FOUND")
> endif()
> 
> It works fine if I search for "cxcore" for which it returns me libcxcore.so
> and the OpenCV_LIBRARY_RELEASE
> as /homes/ahanda/openCV2.1/OpenCV-2.1.0/opencvinstall/lib/libcxcore.so
> 
> However if I try to search for cxcore21 or cxcore210 or even
> libcxcore.so.2.1.0 it won't return me anything and I'd always see LIBRARY
> NOT FOUND being printed.
> 
> Could anyone please let me know how to really search for libcxcore.so.2.1.0

You can't I think. Thats simply not how cmake or the linker work. The
linker during the compilation phase will always link against
lib<name>.so. So you need to make sure that your lib<name>.so is from
cxcore 2.1.0 and search simply for cxcore.

If you want to make sure that a user has at least cxcore 2.1.0 installed
you'll need to use other means to find out the version number of the
installed library. Usually such libs provide a header with version
numbers which you can read. Or it may have a pkgconfig file for which
cmake has extra macros to read them. In worst case you could try to grep
for the version number in the output of strings running over the found
library.

Andreas



More information about the CMake mailing list