[CMake] Handling library interdependencies

Mark Lohry mlohry at gmail.com
Tue Jun 16 16:41:51 EDT 2009


Novice question:

I have a number of subdirectories, each containing source to be built into
their own libraries, which contain many interdependencies. I'm trying to
build an executable to link against these libraries, and I'm getting a
console full of "undefined reference to..." errors on linking step. The
libraries and executable source all compile individually without issue.

Structure is like so:

# top-level CMakeLists.txt
project( proj )
ADD_SUBDIRECTORY( lib )
ADD_SUBDIRECTORY( src )


# /lib/CMakeLists.txt
ADD_SUBDIRECTORY( lib1 )
ADD_SUBDIRECTORY( lib2 )


# /lib/lib1/CMakeLists.txt
include_directories( ${proj_SOURCE_DIR}/lib )
set( lib1_SRCS
  ..... bunch of c++ sources )
add_library( lib1 SHARED ${lib1_SRCS} )


# /lib/lib2/CMakeLists.txt
include_directories( ${proj_SOURCE_DIR}/lib )
set( lib2_SRCS
  ..... bunch of c++ sources )
add_library( lib2 SHARED ${lib2_SRCS} )


# src/CMakeLists.txt
include_directories( ${proj_SOURCE_DIR}/lib )
set( execthing_SRCS
 .... bunch of C++ sources )
add_executable( execthing ${execthing_SRCS} )
target_link_libraries( execthing lib1 lib2 )


All the tutorials I've been reading suggest that this is all that is
necessary to build libraries and cmake will handle the dependencies, but
linking is failing. System is linux 2.6, gcc 4.2.1. Any point in the right
direction would be appreciated. Let me know what other info is needed.

Thanks in advance,
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090616/e10fa5b8/attachment-0001.htm>


More information about the CMake mailing list