Xcode Question, how to run one file at a time?
I keep getting this error: "Linker command failed with exit code 1" and I've noticed that it occurs when i use the "int main" method in multiple files. Furthermore, when I try to run a simple return 0 file, my "hello world" file still gives results to the console. So my assumption is that xcode is running all of the files in the project at the same time causing me to have a duplication error when I repeat method names (such as "int main"). How do I only run one file at a time? These are C files by the way, I'm using xcode as a tool to practice my c programming before next semester. Thanks for your help!
It sounds like you're trying to build multiple programs. The problem is you have a single "target" which is what Xcode uses to define what goes into an application.
You will need to create a separate target for each of your programs and assign target membership for your source files. Go to File->New->Target
to create a new target. From the sounds of it, you are creating a command-line C program, so you will want to create a Command-Line Tool
found under OS X-> Application
.
Alternatively, you could also create separate projects for each program. See File->New->Program
As yet another alternative, assuming you are creating command-linen tools, if you wish you can use Xcode merely as an editor and build the program from the commandline (which you may have to do for your classes anyway). You can do this by creating your .c files and opening them in Xcode. Save the files to the same folder. To compile from the commandline, run something like the following in Terminal:
gcc -Wall file1.c file2.c -o myprogram
You would then run your program by giving:
./myprogram
If that doesn't work, make sure the command line tools are installed.
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