[CMake] RE: Trouble with interdependent libraries
Tal Blum
tblum at bbn.com
Wed Nov 28 14:32:38 EST 2007
This might be circular dependencies between your LibC and LibB libraries. I
had such problem where it worked on Windows but not on Linux. If this is the
case you can solve it by:
TARGET_LINK_LIBRARIES (A B C B)
Or
TARGET_LINK_LIBRARIES (A B C B C.)
I solved it by defining a library that combines both libraries to one
library and add the library file to the source files of every executable
that links against them.
IF(UNIX)
# This is to overcome circular dependencies between ${BUILD_LANGUAGE} and
Generic libs.
# the benefit of doing it this way is that the combined library is only
created once.
SET (COMBINED_LIB ${CMAKE_BINARY_DIR}/lib${BUILD_LANGUAGE}Generic.a)
ADD_CUSTOM_COMMAND(OUTPUT ${COMBINED_LIB}
COMMAND ar ARGS crsv ${COMBINED_LIB} `find ./${BUILD_LANGUAGE} -name
'*.o'` `find ./Generic -name '*.o'`
DEPENDS ${BUILD_LANGUAGE} ${GENERIC_LIBRARIES}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Creating a single library from ${BUILD_LANGUAGE} & Generic"
)
# adding the library to SOURCE_FILES creates a dependency of the project
on the library.
SET (SOURCE_FILES ${SOURCE_FILES} ${COMBINED_LIB})
ENDIF(UNIX)
It is not so elegant, but it works.
>I'm working with 3 CMakeLists.txt files I didn't write, so I'm trying to
figure out the reasoning behind them.
>
>-Application A has a CMakeLists.txt file with TARGET_LINK_LIBARIES(LibB,
LibC). -LibB and LibC each have their own subfolders and CMakeLists.txt
>file, and use ADD_LIBRARY to declare their sources to be a library. -LibB
uses some classes defined in LibC.
>
>Under windows, I can run cmake, compile and link without errors. On Linux,
I get linker errors that LibB's uses of LibC are undefined >references. I
tried adding TARGET_LINK_LIBRARY(LibC) to LibB's CMakeLists.txt file, but
that didn't fix the error. Any ideas?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20071128/e9c5cd1e/attachment.htm
More information about the CMake
mailing list