cmake生成Xcode-project - 发布 - 构建工作,但归档失败链接器错误 [英] cmake generated Xcode-project - release-build works but archive fails on linker errors

查看:408
本文介绍了cmake生成Xcode-project - 发布 - 构建工作,但归档失败链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Xcode 6.3.1,CMake 3.2.2

Using Xcode 6.3.1, CMake 3.2.2

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

I have a project which links with a library. This library is included in the xcode-project as code, compiled and then linked with the main executable.

项目是使用cmake生成的。 CMakeLists.txt的一些提取:

The project is generated with cmake. Some extracts of the 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),它编译和链接问题。

After generating my xcodeproj, I build a normal version ( cmd + B ) which compiles and links (and runs) without issues. When I try to archive however it fails on a linker-error.

使用命令行xcodebuild我比较了两个版本,一些提取:

Using commandline xcodebuild I compared both versions, some extracts:

release-build

release-build

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

archive-build

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'

所以对于release-builds,它正确地使用了cmake指定的构建路径。对于archive-builds,它忽略构建路径,而是编译并将结果库放在default-intermediate-folder中 - 但是当链接到exe时,它再次查看cmake指定的构建路径,然后失败找到库。

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.

它看起来像是xcode中的一个错误,因为cmake覆盖了构建路径...?

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

推荐答案

同时我发现了一个解决方法,所以至少它存档没有链接器错误。在cmakelists.txt中指定每个配置构建路径,如下所示:

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将编译库 - 稍后链接

And archive will compile the library - and find it later, when linking

这篇关于cmake生成Xcode-project - 发布 - 构建工作,但归档失败链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆