[CMake] TARGET_LINK_LIBRARIES got a link error

Rolf Eike Beer eike at sf-mail.de
Fri Apr 12 02:28:08 EDT 2013


Lloyd wrote:
> Hi,
> 
> I am new to Cmake and at present exploring its features for migrating our
> projects build system to use it.
> 
> I have main source folder inside that another folder contains the source
> for our custom library.
> 
> I understand that the problem is with my cmake file. Through that the
> generated project cannot locate the location of my library build location.
> What is the right way to solve this kind of problem?
> 
> Thanks,
>   Lloyd
> 
> As a sample I am including my Cmake code
> 
> #Cmake file of library source code
> #Path-> Myproject/src/lib/reverse
> 
> cmake_minimum_required (VERSION 2.6)
> 
> if(WIN32)
> SET (REV_SRC reverse.cpp reverse.h)
> else(WIN32)
> SET (REV_SRC reverse.cpp)
> endif(WIN32)

There is no reason for this. CMake knows that it does not have to compile 
header files, so it wont add compile rules for them e.g. in Makefiles. Just 
always add them to the project, this has some additional benefits for 
generated headers and the like.

> ADD_DEFINITIONS(-DREVERSE_EXPORTS)
> 
> ADD_LIBRARY(Reverse SHARED ${REV_SRC})
> 
> 
> 
> This is my CMake file inside the Src folder
> 
> #Cmake file of main source code
> #Path-> Myproject/src/
> cmake_minimum_required (VERSION 2.6)
> 
> FIND_PACKAGE(Qt4 REQUIRED)
> INCLUDE(${QT_USE_FILE})
> INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lib/reverse)
> 
> ADD_SUBDIRECTORY(lib/reverse)
> 
> ADD_EXECUTABLE(Tutorial main.cpp)
> 
> TARGET_LINK_LIBRARIES(Tutorial ${QT_LIBRARIES})
> #############################################################
> #I understand that the problem is here, because it cant locate my library.
> TARGET_LINK_LIBRARIES(Tutorial reverse)
> #############################################################

You just need to make sure that it goes into the lib folder first, before 
going into src. So the top level CMakeLists.txt should have

add_subdirectory(lib)
# or lib/reverse above, depending if you have something in lib/
add_subdirectory(src)

Eike
-- 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130412/f0394a31/attachment.pgp>


More information about the CMake mailing list