生成Xcode-project - release-build工作,但存档失败的链接错误



使用Xcode 6.3.1, CMake 3.2.2

我有一个项目链接到一个库。这个库作为代码包含在xcode-project中,编译后链接到主可执行文件。

项目是用cmake生成的。CMakeLists.txt的一些摘录:

add_library(mylib ${mylib_HEADERS} pch.cpp source/mylib/xxx.cpp)
...
add_executable(${MAIN_BINARY_NAME} MACOSX_BUNDLE ${MAIN_HEADERS} ${MAIN_CODE_FILES} ${MAIN_ICON_FILES} ${MAIN_DYLIBS} )
target_link_libraries (${MAIN_BINARY_NAME} mylib)

在生成我的xcodeproj之后,我构建了一个正常的版本(cmd + B),它编译和链接(和运行)没有问题。但是,当我尝试存档时,它会因链接错误而失败。

使用xcodebuild命令行比较了两个版本,其中一些摘录:

发布构建版本

Libtool /Users/username/dev/MyProject/cmake-master/libs/mylib/RelWithDebInfo/libmylib.a normal x86_64

archive-build

Libtool /Users/username/Library/Developer/Xcode/DerivedData/MyProject-facomnlcdbuduqeohionewjyectq/ArchiveIntermediates/MyProject/IntermediateBuildFilesPath/UninstalledProducts/libmylib.a normal x86_64
...
Ld /Users/username/Library/Developer/Xcode/DerivedData/MyProject-facomnlcdbuduqeohionewjyectq/ArchiveIntermediates/MyProject/InstallationBuildProductsLocation/Applications/MyProject.app/Contents/MacOS/MyProject normal x86_64
...
clang: error: no such file or directory: '/Users/username/dev/myproject/cmake-master/libs/mylib/RelWithDebInfo/libmylib.a'

So for release-builds, it correctly uses the build path specified by cmake. For archive-builds, it ignores the build-path and instead compiles and puts the resulting library in the default-intermediate-folder - but then when linking with the exe it does again look in the cmake-specified build-path and then fails to find the library.

It looks like a bug in xcode, which turns up because cmake overrides the build-path... ?

In the meanwhile I found a work-around, so at least it Archives without linker errors. Specify a "per configuration build path" in the cmakelists.txt like this:

set_target_properties(mylib PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/library)

和archive将编译库-并在链接

时找到它

最新更新