[CMake] Splitting in multiple directories

Alexander Neundorf a.neundorf-work at gmx.net
Wed Jul 13 16:48:17 EDT 2016


On Tuesday 12 July 2016 09:00:43 portolan wrote:
> Hello,
> 
> I am new to Cmake and I have a pretty strange behaviour: I set my c+++
> project to work with a single CMakefile.txt, and now I am trying to have
> a more proper version with a .txt for each subdirectory
> 
> Pretty normal stuff, my source tree is:
> 
> <root> --Lib                (my sources)
> 
>               --Logger   (as the name says, a logger)
> 
>              --Lib_UT  (Unitary tests for CxxTest)
> 
>              --Lib_UT_Runner      (the Cxx-generated test runner)
> 
> 
> I have a Lib_UT/CMakefile.txt and Lib_UT_Runner/CMakefile.txt, I call
> them using include_directory(Lib_UT) and


I guess you mean add_subdirectory() ?


> include_directory(Lib_UT_Runner) and everything is fine (apart from the
> runner executable being in a different directory)
> 
> BUT is I do the same for the logger, Lib_UT_Runner has a linking error
> where it cannot link to LibLogger.so. But the shared library is
> correctly generated and it is on the command line :
> 
> /usr/bin/c++      -lpthread CMakeFiles/Lib_UT_Runner.dir/Runner.cpp.o
> -o Lib_UT_Runner ../Lib_UT/libLib_UT.so ../libLib.so ../libLogger.so
> -lpthread
> -Wl,-rpath,/home/michele/mast-devel/cmake_debug/Lib_UT:/home/michele/mast-de
> vel/cmake_debug:/home/michele/mast-devel/cmake_debug/Logger
> 
> I tried using find_library, but I always get not-found


what's the error message ?

Posting relevant bits of your CMakeLists.txt (related to subdirs, creating 
targets and linking) would be helpful too.

Alex



More information about the CMake mailing list