0

I cannot force cmake to search the library in the subdirectory /usr/local/lib/db5.

To search for libraries I use the following script:

link_directories(/usr/local/lib/db5 /usr/local/lib /usr/lib)

set (LIBRARIES
        c m util ssl pthread db)

foreach (LIBRARY ${LIBRARIES})
    find_library ("${LIBRARY}_FOUND" ${LIBRARY})
    message (STATUS "Check the ${LIBRARY} is installed: " ${${LIBRARY}_FOUND})
    if ( "${${LIBRARY}_FOUND}" STREQUAL "${LIBRARY}_FOUND-NOTFOUND" )
        message (STATUS "Adding library sources")
        add_subdirectory (../${LIBRARY} lib/${LIBRARY})
    endif ()
endforeach ()

The library is definitely present in the directory.

ogogon@:/usr/local/src/util# ls /usr/local/lib/db5
libdb_cxx-5.3.a     libdb_cxx-5.3.so.0.0.0  libdb_cxx.so        libdb_stl-5.3.so.0  libdb_stl.a     libdb-5.3.so        libdb-5.so
libdb_cxx-5.3.so    libdb_cxx-5.so      libdb_stl-5.3.a     libdb_stl-5.3.so.0.0.0  libdb_stl.so        libdb-5.3.so.0      libdb.a
libdb_cxx-5.3.so.0  libdb_cxx.a     libdb_stl-5.3.so    libdb_stl-5.so      libdb-5.3.a     libdb-5.3.so.0.0.0  libdb.so

Library search does not lead to success.

ogogon@ot:/usr/local/src/util# ./configure 
-- The C compiler identification is Clang 6.0.0
-- The CXX compiler identification is Clang 6.0.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check the c is installed: /usr/lib/libc.so
-- Check the m is installed: /usr/lib/libm.so
-- Check the util is installed: /usr/lib/libutil.so
-- Check the ssl is installed: /usr/lib/libssl.so
-- Check the pthread is installed: /usr/lib/libpthread.so
-- Check the db is installed: db_FOUND-NOTFOUND
-- Adding library sources
CMake Error at CMakeLists.txt:27 (add_subdirectory):
  add_subdirectory given source "../db" which is not an existing directory.


-- Configuring incomplete, errors occurred!
See also "/usr/local/src/util/CMakeFiles/CMakeOutput.log".

If I remove the library db from the list - everything goes fine.

ogogon@ot:/usr/local/src/util# ./configure 
-- The C compiler identification is Clang 6.0.0
-- The CXX compiler identification is Clang 6.0.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check the c is installed: /usr/lib/libc.so
-- Check the m is installed: /usr/lib/libm.so
-- Check the util is installed: /usr/lib/libutil.so
-- Check the ssl is installed: /usr/lib/libssl.so
-- Check the pthread is installed: /usr/lib/libpthread.so
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/src/util

What am I doing wrong? How do I solve this problem?

ogogon
  • 70
  • 5
  • 1
    You are probably looking for the way for hint `find_library` call about the library location. If so, see that question: https://stackoverflow.com/questions/12075371/cmake-find-library-custom-library-location. – Tsyvarev Feb 20 '19 at 09:15
  • It is not clear to me what you want to do actually. *add_subdirectory* basically adds a subproject to your project. You combine this with *find_library*, which is used to find third-party libraries on your OS. Can you clarify what you would like to do? – carlosvalderrama Feb 20 '19 at 09:15
  • I would like CMake to look for libraries in some subdirectories. – ogogon Feb 21 '19 at 22:36
  • Now I solved this problem like this: – ogogon Feb 21 '19 at 22:37

1 Answers1

0

Now I solved this problem like this:

set (LIBPATHS /usr/local/lib/db5 /usr/local/lib /usr/lib libs5)

set (LIBRARIES
        c m util db ssl pthread)

foreach (LIBRARY ${LIBRARIES})
    find_library ("${LIBRARY}_FOUND" ${LIBRARY} PATHS ${LIBPATHS})
    message (STATUS "Check the ${LIBRARY} is installed: " ${${LIBRARY}_FOUND})
    if ( "${${LIBRARY}_FOUND}" STREQUAL "${LIBRARY}_FOUND-NOTFOUND" )
        message (STATUS "Adding library sources")
        add_subdirectory (../${LIBRARY} lib/${LIBRARY})
    endif ()
endforeach ()

But, if the version of the Berkley DB library changes, the paths will have to be adjusted. Is there a way to write something like /usr/local/lib/db* ?

ogogon
  • 70
  • 5