[CMake] Linking Libraries

abboti at rpi.edu abboti at rpi.edu
Mon Nov 12 12:32:06 EST 2007


I've created a project (Farsight) that has this top-level CMakeLists file 
(segment shown).  The subdirs also have theirs.  The cpp files in /seg
use VTK libraries.  I have found that the project compiles using MS
Visual Studio, but not using g++.  

To get g++ to work I added this to the CMakeLists shown below:
LINK_LIBRARIES(
  VTKCommon
  VTKIO
  VTKFiltering
)

I understand this to be an old command that is no longer necessary, and I 
don't want to have it in this CMakeLists file because I don't need to
know what each module (subdir) requires for libraries.


################################################################################
# Snippet of Top-Level CMakeLists.txt  
################################################################################

SUBDIRS( wrap )


# here we instruct CMake to build "Farsight" executable from all 
# source files and place it in the "bin" folder

ADD_EXECUTABLE( Farsight 
    ${FARSIGHT_SRCS} 
)

# last thing we have to do is to tell CMake what libraries our executable 
needs,
# luckily FIND_PACKAGE prepared QT_LIBRARIES variable for us:
TARGET_LINK_LIBRARIES( Farsight 
)



#####################################################################
The CMakeLists.txt in \wrap
#####################################################################
SET( MY_WRAPPERS_SRCS
    itkimage2qimage.cpp
    qimage2itkimage.cpp
    vtkLSMReader.cxx
)

SET( MY_WRAPPERS_HDRS
    qimage2itkimage.h
    vtkLSMReader.h
    vtkBXDProcessingWin32Header.h
)

ADD_LIBRARY( fswrappers 
             ${MY_WRAPPERS_SRCS} 
             ${MY_WRAPPERS_HDRS} 
)

TARGET_LINK_LIBRARIES( fswrappers ${QT_LIBRARIES} VTKCommon VTKFiltering )








More information about the CMake mailing list