简体   繁体   English

CMake生成的Xcode项目无法找到从Xcode构建的二进制“产品”

[英]CMake generated Xcode project fails to find the binary “Products” that are built from Xcode

I am trying to use CMake Generated Xcode project. 我正在尝试使用CMake Generated Xcode项目。 Everything looks good when building, except that Xcode can not find the binaries that are built. 构建时一切看起来都很好,除了Xcode找不到构建的二进制文件。 Below is a screenshot i took after successfully build the product. 下面是我成功构建产品后的截图。 I can see them in the project source directory. 我可以在项目源目录中看到它们。 However, notice that the Xcode showing RED "HelloWorld", which means it can not find the products. 但是,请注意Xcode显示RED“HelloWorld”,这意味着它无法找到产品。

显示红色的产品截图

Configurations: CMake 2.8.6 with Xcode 4.2 on Lion 10.7.2 配置:在Lion 10.7.2上使用Xcode 4.2进行CMake 2.8.6

This is CMakeLists.txt 这是CMakeLists.txt

project(HelloWorld)

add_executable(${PROJECT_NAME} HelloWorld.cpp)

This is the source code for HelloWorld.cpp 这是HelloWorld.cpp的源代码

#include <iostream>

int main(){
    std::cout << "HelloWorld!" << std::endl;

    return 0;
}

I tried to create a raw project directly from Xcode, after compiles, the products shows black instead of red font, which means Xcode found the products. 我试图直接从Xcode创建一个原始项目,编译后,产品显示黑色而不是红色字体,这意味着Xcode找到了产品。 So i am sure this is related to CMake Generated Xcode project. 所以我相信这与CMake Generated Xcode项目有关。

Anyone got any idea? 有人有任何想法吗? how to fix this? 怎么解决这个问题?

I had the same issue. 我遇到过同样的问题。 For me it was caused by an extra "build" directory in the search path Xcode was using to find the product. 对我来说,这是由Xcode用于查找产品的搜索路径中的额外“构建”目录引起的。 I hacked around the problem by putting the products in the location Xcode expects, ie I added the extra "build" directory.: 我通过将产品放在Xcode所期望的位置来解决问题,即我添加了额外的“构建”目录:

if(CMAKE_GENERATOR STREQUAL Xcode)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/build/Debug)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/build/Release)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/build/Debug)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/build/Release)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/build/Debug)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/build/Release)
endif()

The xcode project file (which I guess, in your case would be named something like HelloWorld.xcproject/project.pbxproject , will have SYMROOT definitions for each of the build configurations per target. xcode项目文件(我猜,在你的情况下会被命名为HelloWorld.xcproject/project.pbxproject ,它将为每个目标的每个构建配置提供SYMROOT定义。
You can either change all the SYMROOT definitions to the same value or remove all of those (xcode will default to "build"). 您可以将所有SYMROOT定义更改为相同的值,也可以删除所有这些定义(xcode将默认为“build”)。
Project, if open, should autoreload. 项目,如果打开,应自动加载。 Select ALL_BUILD or HelloWord, clean and build. 选择ALL_BUILD或HelloWord,清理并构建。

Not sure if it is an issue with the way cmake adds the SYMROOT. 不确定cmake添加SYMROOT的方式是否存在问题。
Note: I know this only hints at what the problem could be and not a solution but am not allowed to add comments yet :) 注意:我知道这只是暗示问题可能是什么而不是解决方案但是不允许添加评论:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM