xcode 项目中的多个 .cpp 程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7974259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple .cpp programs in xcode project?
提问by David
I'm using Xcode to do the Project Euler problems in C++. I wanted to keep everything organized, so I decided to make a single project that would include all my .cpp files, like in visual studio. The problem that I am encountering is I have one project called "Project Euler" and then I wanted to have Problem1.ccp, Problem2.cpp, etc. enabling the ones I want to run. When I did that, I got an error "Apple Mach-O Linker Error". Does anyone know how I could do what I'm trying to do with Xcode?
我正在使用 Xcode 来解决 C++ 中的 Project Euler 问题。我想让一切井井有条,所以我决定制作一个包含我所有 .cpp 文件的项目,就像在 Visual Studio 中一样。我遇到的问题是我有一个名为“Project Euler”的项目,然后我想让 Problem1.ccp、Problem2.cpp 等启用我想要运行的项目。当我这样做时,我收到一个错误“Apple Mach-O 链接器错误”。有谁知道我如何用 Xcode 做我想做的事?
回答by brian.schiller.uml
Yes, you want to add a new Target using justin's steps.
是的,您想使用 justin 的步骤添加新目标。
You also need to understand what a target is: http://developer.apple.com/library/ios/#featuredarticles/XcodeConcepts/Concept-Targets.html
您还需要了解什么是目标:http: //developer.apple.com/library/ios/#featuredarticles/XcodeConcepts/Concept-Targets.html
and how to run and compile the separate files: http://developer.apple.com/library/ios/#recipes/xcode_help-scheme_editor/Articles/SchemeBuild.html
以及如何运行和编译单独的文件:http: //developer.apple.com/library/ios/#recipes/xcode_help-scheme_editor/Articles/SchemeBuild.html
To paraphrase, a target is a completely separate product contained in the same Xcode project.
换句话说,目标是包含在同一个 Xcode 项目中的完全独立的产品。
When you want to change which target you're running/compiling/analyzing you need to adjust the scheme. In Xcode version 4.6.2 go to:
当您想更改正在运行/编译/分析的目标时,您需要调整方案。在 Xcode 4.6.2 版中,转到:
Product > Scheme > Desired Target
回答by justin
What you want is one Xcode target per problem (assuming that each problem has a main()
).
您想要的是每个问题一个 Xcode 目标(假设每个问题都有一个main()
)。
To add a target to the current project (Xc4), go to File > New > New Target…
.
要将目标添加到当前项目 (Xc4),请转到File > New > New Target…
。