Hello cmake users!<br><br>I'm quite new to cmake as well as makefiles, and i've bumped the same trouble twice. I'm trying to break a source code into several libraries and a main program. The scenario has one main executable called calClient which uses functions from three libraries, let's say 1A 1B and 2C. Everybody uses library 2C, that is calClient, 1A and 1B. I've stored the source codes of 1A 1C and 2C in a subdirectory called lib/ toghether with a CMakeLists.txt :<br>
<br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">FIND_PACKAGE(YARP REQUIRED)<br><br>SET(PROJECT_LIBS<br> 2C.cpp<br> 2C.h<br> 1B.cpp<br>
1B.h<br> 1A.cpp<br> 1A.hpp<br>)<br><br>add_library(callibs ${PROJECT_LIBS})</blockquote><div><br>In the upper directory, toghether with the source code of the main program, I have:<br><br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
project(calibration)<br><br>cmake_minimum_required(VERSION 2.6)<br><br>set(CMAKE_CXX_FLAGS "-g -Wall")<br><br>set(PROJECT_SRC<br> calClient.cpp<br> calClient.hpp<br> chaser.cpp<br> chaser.hpp<br>)<br>
<br>FIND_PACKAGE(YARP REQUIRED)<br>FIND_PACKAGE(OpenCV REQUIRED)<br><br>add_subdirectory(lib)<br><br>INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/lib)<br>link_directories(lib)<br><br>INCLUDE_DIRECTORIES(${OPENCV_INCLUDE_DIR})<br>
<br>ADD_EXECUTABLE(calClient ${PROJECT_SRC})<br>TARGET_LINK_LIBRARIES( calClient ${OPENCV_LIBRARIES} )<br>TARGET_LINK_LIBRARIES( calClient callibs )<br></blockquote><br></div>Every header includes the headers of the files which contains the functions that it needs. So, calClient.hpp actually includes 1A, 1B and 2C.<br>
<br>The output of the make command is then:<br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">[ 60%] Built target callibs<br>Linking CXX executable calClient<br>
CMakeFiles/calClient.dir/calClient.cpp.o: In function `incrementalCalibrate(yarp::dev::IPositionControl*, yarp::dev::IEncoders*)':<br>/home/pmonso/YARP/Calclient/calClient.cpp:276: undefined reference to `print_double_array(double const*, int)'<br>
/home/pmonso/YARP/Calclient/calClient.cpp:277: undefined reference to `print_double_array(double const*, int)'<br>/home/pmonso/YARP/Calclient/calClient.cpp:295: undefined reference to `print_double_array(double const*, int)'<br>
CMakeFiles/calClient.dir/calClient.cpp.o: In function `calibrate(yarp::dev::IPositionControl*, yarp::dev::IEncoders*)':<br>/home/pmonso/YARP/Calclient/calClient.cpp:155: undefined reference to `print_double_array(double const*, int)'<br>
CMakeFiles/calClient.dir/calClient.cpp.o: In function `randomCalibrate(yarp::dev::IPositionControl*, yarp::dev::IEncoders*)':<br>/home/pmonso/YARP/Calclient/calClient.cpp:207: undefined reference to `print_double_array(double const*, int)'<br>
CMakeFiles/calClient.dir/calClient.cpp.o:/home/pmonso/YARP/Calclient/calClient.cpp:208: more undefined references to `print_double_array(double const*, int)' follow<br>collect2: ld returned 1 exit status<br>make[2]: *** [calClient] Error 1<br>
make[1]: *** [CMakeFiles/calClient.dir/all] Error 2<br>make: *** [all] Error 2<br></blockquote><br><br>The function print_double_array is located in the 2C source and header files which, as I said, is included in calClient header as well as in headers of 1A and 1B.<br>
<br>Does somebody know why linking fails? What I am doing wrong? It's driving me nuts!<br><br>Thanks alot for your help!<br><br>pol<br>