cmake os x失败,没有特定的存档成员 [英] cmake os x failure ar no archive members specific
问题描述
我有一个简单的cmake项目,无法在OS X 10.8.4上进行编译. cmake/make程序在Linux上运行良好,但在OS X上却出现此错误:
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
我在两个平台上都使用Eclipse CDT4 Generator Unix MakeFile.这似乎与两个系统上ar之间的差异有关.但是,我在Google上找不到很多可以帮助我解决问题的信息.
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.
这是您的更多信息
src/CMakeList.txt
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
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:
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)
推荐答案
您不能从一个头文件创建库:
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})
这就是为什么您明确设置LINKER_LANGUAGE
的原因-没有没有链接并且cmake感到困惑.
that's the reason why you set LINKER_LANGUAGE
explicitly - there is nothing to link and cmake is confused.
所以include_directories
就足够了:
include_directories(${PROJECT_SOURCE_DIR}/lib)
顺便说一句:
如果您指定REQUIRED
,则无需检查ITK_FOUND
:
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 )
来自文档:
The REQUIRED option stops processing with an error message if the package cannot be found.
PROJECT_SOURCE_DIR
不必等于itkNormals_SOURCE_DIR
(您可以从其他项目使用此文件):
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")
这篇关于cmake os x失败,没有特定的存档成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!