Xcode:多个项目,多个主要可执行文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4019742/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:52:37  来源:igfitidea点击:

Xcode: multiple projects, more than one main executable

c++xcodexcodebuild

提问by slik

Hi I'm new to Xcode. I'm trying to learn c++ and I was wondering if it is possible to have multi projects and choose which project should run. I used ms visual studios before and I like how under a solution I can create multiple projects and choose which one is the executable one. Xcode also has targets not exactly sure what they are maybe they play a role? I tried messing around but I constantly have issue because of duplicate mains. I'm going through a chapter and there are case studies. I'm trying to keep every chapter organized in one project well something like that. Any help thanks!

嗨,我是 Xcode 的新手。我正在尝试学习 C++,我想知道是否可以有多个项目并选择应该运行哪个项目。我之前使用过 ms Visual Studios,我喜欢在一个解决方案下我可以创建多个项目并选择哪个是可执行的。Xcode 也有不完全确定它们是什么的目标,也许它们发挥了作用?我试图搞砸,但由于重复的电源,我经常遇到问题。我正在阅读一章并且有案例研究。我正在努力使一个项目中的每一章都井井有条。任何帮助谢谢!

回答by nonVirtualThunk

Xcode targets are probably what you are looking for. You can have many targets in a single project, and whichever one you select as active will be used when you tell Xcode to compile or run. If you are having problems with duplicate mains, you probably have all of your .cpp files in all of your targets. If you have main1.cpp and main2.cpp in the same target, Xcode will attempt to use both of them and run into a conflict. Including all common files in all targets, but only the appropriate main files will likely solve your problems.

Xcode 目标可能就是您正在寻找的。您可以在一个项目中拥有多个目标,当您告诉 Xcode 编译或运行时,将使用您选择为活动的任何一个。如果您遇到重复电源的问题,您可能在所有目标中都有所有 .cpp 文件。如果您在同一个目标中有 main1.cpp 和 main2.cpp,Xcode 将尝试同时使用它们并遇到冲突。包括所有目标中的所有公共文件,但只有适当的主文件可能会解决您的问题。

回答by sharad

for creating a new main.cpp file you should go to

要创建一个新的 main.cpp 文件,你应该去

File-New-target.

文件-新-目标。

After it gets created just select your file here to choose which file you want to execute:

创建后,只需在此处选择您的文件即可选择要执行的文件:

enter image description here

在此处输入图片说明

回答by Johnny Well

Actually you can create a workspace, then create each exercise as a project or as a target inside a root project, the second option is preferred if the exercises need to share the same libs and setup.

实际上,您可以创建一个工作区,然后将每个练习创建为一个项目或作为根项目中的目标,如果练习需要共享相同的库和设置,则首选第二个选项。

To select the active scheme to debug and run you can use this selection menu close to debug controls.

要选择要调试和运行的活动方案,您可以使用靠近调试控件的此选择菜单。

enter image description here

在此处输入图片说明