[Cmake] Specifying static or dynamic linking of external libraries?

William A. Hoffman bill.hoffman at kitware.com
Tue Oct 22 21:20:14 EDT 2002


OK, I see the problem, you should see the Examples directory in VTK.
(Examples/Tutorial/Step1/Cxx)

You want something like this:

PROJECT(calWidgets)

# ask cmake to find VTK
INCLUDE (${CMAKE_ROOT}/Modules/FindVTK.cmake)
IF (USE_VTK_FILE)
   INCLUDE(${USE_VTK_FILE})
ENDIF (USE_VTK_FILE)

# create a variable with your sources
SET(Project_sources
    myImagePlaneWidget.cxx
    myImageViewer.cxx )

# create your library from the sources
ADD_LIBRARY(calWidgets STATIC ${Project_sources})
# create an executable using test.cxx
ADD_EXECUTABLE(testImagePlaneWidget test.cxx)
# now link calWidgets and any libraries that you directly use out of VTK:
TARGET_LINK_LIBRARIES(testImagePlaneWidget calWidgets vtkHybrid 
vtkRendering vtkIO)


As long as the VTK you point cmake at is built static, things should work well.
cmake will pull in all the extra libraries used by vtkHybrid vtkRendering 
and vtkIO.

CMake is just doing what you told it to do.   It is linking all the 
libraries in the order that
you gave them to it.   Since you did not use the UseVTK.cmake file, cmake does
not know about the extra libraries needed by VTK.

-Bill

At 03:17 PM 10/22/2002 -0700, Thomas Deschamps wrote:
>-> CMake-1.4.5, I've installed it yesterday.
>Here is the content of my CMakeList.txt:
>---------------------------------------------------------------------------------
>PROJECT(calWidgets)
>INCLUDE(${CMAKE_ROOT}/Modules/FindOpenGL.cmake)
>INCLUDE_DIRECTORIES(
>    /usr/local/include
>    /usr/local/include/vtk )
>
>LINK_LIBRARIES(
>        /usr/local/lib/libvtkftgl.a
>        /usr/local/lib/libvtkfreetype.a
>        /usr/local/lib/libvtkCommon.a
>        /usr/local/lib/libvtkFiltering.a
>        /usr/local/lib/libvtkGraphics.a
>        /usr/local/lib/libvtkHybrid.a
>        /usr/local/lib/libvtkImaging.a
>        /usr/local/lib/libvtkIO.a
>        /usr/local/lib/libvtkRendering.a
>        ${CMAKE_X_LIBS}
>        ${CMAKE_THREAD_LIBS} )
>
>SOURCE_FILES(Project_sources
>    myImagePlaneWidget.cxx
>    myImageViewer.cxx )
>
>ADD_LIBRARY(calWidgets STATIC Project_sources)
>ADD_EXECUTABLE(testImagePlaneWidget Project_sources test.cxx)
>---------------------------------------------------------------------------------
>
>William A. Hoffman wrote:
>
>>What version of cmake are you using?
>>
>>-Bill
>
>
>
>_______________________________________________
>Cmake mailing list
>Cmake at public.kitware.com
>http://public.kitware.com/mailman/listinfo/cmake






More information about the CMake mailing list