[CMake] how to write a cmakelist to call a function in another c or cxx file

Yixun Liu enjoywm at cs.wm.edu
Sat Jan 16 09:40:55 EST 2010


Hi,
I am not familiar with writing CMakelist.
I have a simple cmakelist file as following.

# This project is designed to be built outside the Insight source tree.
PROJECT(main)

# Find ITK.
FIND_PACKAGE(ITK REQUIRED)
IF(ITK_FOUND)
  INCLUDE(${ITK_USE_FILE})
ENDIF(ITK_FOUND)

FIND_PACKAGE(VTK REQUIRED)
IF(VTK_FOUND)
  INCLUDE(${VTK_USE_FILE})
ENDIF(VTK_FOUND)

ADD_EXECUTABLE(main main.cxx  )

TARGET_LINK_LIBRARIES(main ITKCommon ITKIO vtkCommon vtkIO )

It works well.
Now I need to ,in main.cxx,  invoke a function, let's say func(), 
defined in another c file, let's say test.c.

I make the change to main.cxx
func();
main()
{...}

In the makelist file,
ADD_EXECUTABLE(main main.cxx  test.c)

However, after ccmake and then make, I got the error:
main.cxx:(.text+0x10a): undefined reference to `func()'
collect2: ld returned 1 exit status

Thanks for your help.

Yixun




More information about the CMake mailing list