slik
slik

Reputation: 5221

Xcode: multiple projects, more than one main executable

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!

Upvotes: 2

Views: 7660

Answers (3)

sharad
sharad

Reputation: 21

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

File-New-target.

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

enter image description here

Upvotes: 2

Johnny Wellington
Johnny Wellington

Reputation: 139

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

Upvotes: 0

nonVirtualThunk
nonVirtualThunk

Reputation: 2852

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.

Upvotes: 6

Related Questions