我有一个简单的cmake项目,我无法在OS X 10.8.4上编译。 cmake / make过程在Linux上运行良好但在OS X上我收到此错误:
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
我在两个平台上都使用Eclipse CDT4 Generator Unix MakeFile。这似乎与两个系统上的ar之间的区别有关。但是,我在谷歌找不到太多帮助我排除故障。
以下是您的更多信息
的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 /测试/的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)
答案 0 :(得分:7)
您无法从一个头文件创建库:
add_library(ImageFilter itkImageFilter.hxx)
SET_TARGET_PROPERTIES(ImageFilter PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(ImageFilter ${ITK_LIBRARIES})
这就是你明确设置LINKER_LANGUAGE
的原因 - 有没有来链接,而cmake很困惑。
所以include_directories
就足够了:
include_directories(${PROJECT_SOURCE_DIR}/lib)
<强>顺便说一句强>:
如果您指定ITK_FOUND
:
REQUIRED
FIND_PACKAGE (ITK REQUIRED)
IF( ITK_FOUND )
include( ${ITK_USE_FILE} )
ENDIF( ITK_FOUND )
The REQUIRED option stops processing with an error message if the package cannot be found.
PROJECT_SOURCE_DIR
不一定等于itkNormals_SOURCE_DIR
(您可以使用其他项目中的此文件):
include_directories(${PROJECT_SOURCE_DIR}/lib)
可以通过以下方式修复:
include_directories(${itkNormals_SOURCE_DIR}/lib)
include_directories(${CMAKE_CURRENT_LIST_DIR}/../lib)
或只是从父文件中包含:
# src/CMakeLists.txt
include_directories("./lib")