I am using Xcode for c programming. I have a project called system_commands. Inside this project I have a file A, and a file B.
This is file A:
int main(int argc, char *argvector[])
{
char *arguments[] = {"./runProcesses","Hello","World",NULL};
execvp("./runProcesses", arguments);
return 0;
}
File A simply "executes" File B, and file B is here:
int main(int argc, char *argvector[])
{
for(int i = 0; i < argc; i++)
{
printf("%s", argvector[i]);
}
//some forks etc
}
Obviously, Xcode will not allow this, since there are two main methods inside the project. But is there a workaround somehow? Do I really have to create another project, so that the files reside in different projects? Or is there a way I can execvp() a file without main method?
If you don't want two projects, you can create a second target ("File" - "New" - "Target..." and choose another "Console app") for your second program. Put your other main.c
there:
You can also go to the Target settings for the first console app and add a dependency for the second console app, that way, it will build the second, if needed, whenever you run the first one.
Frankly, this multiple target approach is designed when you have an app with some shared code base, but it can be used in this scenario, too.
The other approach is to go ahead and have multiple projects, but work with them under a single "workspace". So, create a folder, create your two projects in that folder, and then create a "Workspace" (which I called "MyProject", in my example below) and add the two xcodeproj
files for the two separate projects ("FirstApp" and "SecondApp" in my example below).
So, in Xcode it looks like:
And in the file system, it looks like:
So, in this case, you have two projects, but you can work with them together under a single workspace, making it really easy to work with both projects at the same time. Just open that xcworkspace
workspace rather than the individual xcodeproj
files.