简体   繁体   English

带有多个cpp文件的Xcode项目

[英]Xcode Project with multiple cpp files

I have a project directory which has multiple cpp files. 我有一个项目目录,其中包含多个cpp文件。 Each of these files has a main function tied to the respective files. 每个文件都有一个与各个文件相关的主函数。 Can i execute each of these files individually or do i have to modify some configurations in Xcode to target each of the files individually. 我可以单独执行这些文件中的每一个,还是必须修改Xcode中的某些配置以单独定位每个文件。 If so, what are steps that i have to take? 如果是这样,我必须采取什么步骤?

This is what the structure looks like in Xcode 这就是Xcode中的结构

Project1
  Project1
    main1.cpp
    main2.cpp
    main3.cpp

It's relatively straight forward to have multiple targets under the same project: 在同一个项目下拥有多个目标相对简单:

  1. Click on your project in the project navigator: 在项目导航器中单击您的项目:

在此输入图像描述

  1. Go to your target, here; 转到你的目标,在这里;

在此输入图像描述

  1. Go to "add target": 转到“添加目标”:

在此输入图像描述

  1. Select "macOS" and scroll down to "command line tool": 选择“macOS”并向下滚动到“命令行工具”:

在此输入图像描述

  1. Give it a name, and finish: 给它一个名字,然后完成:

在此输入图像描述

  1. You'll see both target in the same project: 你会在同一个项目中看到两个目标:

在此输入图像描述

  1. Next to the 'run' and 'stop' buttons, set your active scheme to the desired main file: 在“运行”和“停止”按钮旁边,将您的活动方案设置为所需的主文件:

在此输入图像描述

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

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