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?
To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL.
Start Xcode and choose File / New Project. Click on Other then choose External Build System. Click Next. Input your project name, I use the existing project's name so that the Xcode project file matches.
It turns out that the “Open Project…” dialog in Xcode supports multi-select! So you can Shift-Down/Up to select more than one project, hit Return and all three projects will be opened simultaneously!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With