Hi,

I ran into a weird error about linking a module test against its module.
Building the test driver fails with this error:

/home/espakm/src/NifTK/Code/Gui/MITK/Modules/XnatRest/Testing/XnatRestTest.cpp:52:
undefined reference to `initXnatRest()'

The function is defined in the module.
However, I can link the test against a library that I created manually from
the same sources. (With the add_library CMake function instead of the
MITK_CREATE_MODULE macro.)

Here is the CMakeLists.txt of the module:

------------------------------------------------------------------------------------------------------------------------
# These should be automatically included, but it is not.
include(${CMAKE_SOURCE_DIR}/CMake/PackageDepends/MITK_curl_Config.cmake)

MITK_CREATE_MODULE(XnatRest
  EXPORT_DEFINE XnatRest_EXPORT
  PACKAGE_DEPENDS curl
)

# This library is built from the same sources as the module:
add_library(XnatRest2 ${CPP_FILES})
target_link_libraries(XnatRest2 curl)

# add testing dir
add_subdirectory(Testing)
------------------------------------------------------------------------------------------------------------------------


And this is the CMakeLists.txt from the Testing directory:


------------------------------------------------------------------------------------------------------------------------
MITK_CREATE_MODULE_TESTS()

# This does not help:
#target_link_libraries(XnatRestTestDriver XnatRest)

# Only this solves the linker error:
target_link_libraries(XnatRestTestDriver XnatRest2)
------------------------------------------------------------------------------------------------------------------------


Does somebody have an idea why I cannot link the test against the module,
but can do it to a library that is built from the same sources as the
module?

I put a string constant into the definition of the initXnatRest() function,
just to check if it is built into both libraries. It is, the strings
command has found it in both.

I also added a debugging statement in the mitkMacroModuleTests.cmake file.
Around line 35 I printed the add_executable and target_link_libraries
statements:

    set(TESTDRIVER ${MODULE_NAME}TestDriver)
    message(STATUS "add_executable(${TESTDRIVER} ${MODULETEST_SOURCE}
${MODULE_TEST_GENERATED_MOC_CPP} ${TEST_CPP_FILES})")
    add_executable(${TESTDRIVER} ${MODULETEST_SOURCE}
${MODULE_TEST_GENERATED_MOC_CPP} ${TEST_CPP_FILES})
    message(STATUS "target_link_libraries(${TESTDRIVER} ${MODULE_PROVIDES}
${ALL_LIBRARIES})")
    target_link_libraries(${TESTDRIVER} ${MODULE_PROVIDES} ${ALL_LIBRARIES})

The output:

-- add_executable(XnatRestTestDriver
XnatRestTestDriver.cpp;XnatRestTest.cpp  )
-- target_link_libraries(XnatRestTestDriver XnatRest
curl;Mitk;mbilog;tinyxml;ITKAlgorithms;ITKStatistics;ITKFEM;ITKQuadEdgeMesh;vtkGraphics;vtkCommon;vtkFiltering;vtkftgl;vtkGraphics;vtkHybrid;vtkImaging;vtkIO;vtkParallel;vtkRendering;vtkVolumeRendering;vtkWidgets;vtkjpeg;vtkpng;vtkzlib;vtkexpat;vtkfreetype)

I don't see anything wrong with this.

Any idea?

Thank you very much,
Miklos
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to