4

I have a simple cmake project going that I can't get to compile on OS X 10.8.4. The cmake/make process works great on Linux but on OS X I am getting this error:

Linking CXX static library libImageFilter.a
ar: no archive members specified
...
make[2]: *** [lib/libImageFilter.a] Error 1
make[1]: *** [lib/CMakeFiles/ImageFilter.dir/all] Error 2
make: *** [all] Error 2

I am using the Eclipse CDT4 Generator Unix MakeFile on both platforms. This seems like something to with the difference between ar on the two systems. But, I couldn't find much on google to help me troubleshoot.

Here is some more info for you

src/CMakeList.txt

make_minimum_required(VERSION 2.8)
project(itkNormals)
FIND_PACKAGE (ITK REQUIRED)
IF( ITK_FOUND )
  include( ${ITK_USE_FILE} )
ENDIF( ITK_FOUND )
add_subdirectory(test)
add_subdirectory(lib)

src/lib/CMakeList.txt

add_library(DotImageFilter itkDotImageFilter.h)
SET_TARGET_PROPERTIES(DotImageFilter PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(DotImageFilter ${ITK_LIBRARIES})

add_library(ImageFilter itkImageFilter.hxx)
SET_TARGET_PROPERTIES(ImageFilter PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(ImageFilter ${ITK_LIBRARIES})

src/test/CMakeLists.txt:

include_directories(${PROJECT_SOURCE_DIR}/lib)

add_executable(itkNormalsMain itkNormals.cxx)
TARGET_LINK_LIBRARIES(itkNormalsMain ${ITK_LIBRARIES})
TARGET_LINK_LIBRARIES(itkNormalsMain ImageFilter)
TARGET_LINK_LIBRARIES(itkNormalsMain DotImageFilter)

add_executable(dotTestMain dotTester.cxx)
TARGET_LINK_LIBRARIES(dotTestMain ${ITK_LIBRARIES})
TARGET_LINK_LIBRARIES(dotTestMain ImageFilter)
TARGET_LINK_LIBRARIES(dotTestMain DotImageFilter)

add_executable(IST ImageSourceTest.cxx)
TARGET_LINK_LIBRARIES(IST ${ITK_LIBRARIES})
TARGET_LINK_LIBRARIES(IST ImageFilter)
jmerkow
  • 1,811
  • 3
  • 20
  • 35

1 Answers1

8

You can't create library from one header file:

add_library(ImageFilter itkImageFilter.hxx)
SET_TARGET_PROPERTIES(ImageFilter PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(ImageFilter ${ITK_LIBRARIES})

that's the reason why you set LINKER_LANGUAGE explicitly - there is nothing to link and cmake is confused.

So include_directories is enough:

include_directories(${PROJECT_SOURCE_DIR}/lib)

BTW:

You don't need to check ITK_FOUND if you specify REQUIRED:

FIND_PACKAGE (ITK REQUIRED)
IF( ITK_FOUND )
  include( ${ITK_USE_FILE} )
ENDIF( ITK_FOUND )

from documentation:

The REQUIRED option stops processing with an error message if the package cannot be found.


PROJECT_SOURCE_DIR is not necessary equal itkNormals_SOURCE_DIR (you may use this file from other project):

include_directories(${PROJECT_SOURCE_DIR}/lib)

Can be fixed one of this way:

include_directories(${itkNormals_SOURCE_DIR}/lib)
include_directories(${CMAKE_CURRENT_LIST_DIR}/../lib)

or simply include from parent file:

# src/CMakeLists.txt
include_directories("./lib")
  • This is a good guide. And the tips are very helpful I haven't been able to find a good ground-up guide for CMake. I haven't coded in a compiled language in a long time, so I a bit rusty on library generation (and when I did CMake didn't exist yet!). I ended up putting all the source files into one library. – jmerkow Nov 14 '13 at 22:00
  • This is not works for me but maybe I'm doing it wrong. Parent file is CMakeLists.txt ?? – Sebastianor Mar 14 '16 at 08:21
  • When I add "include_directories("./lib")" In CMakeList.txt the output error is the same:( – Sebastianor Mar 14 '16 at 08:34
  • Here is my question http://stackoverflow.com/questions/36632618/unable-to-build-cmake-project-on-macos – Sebastianor Apr 14 '16 at 19:52