Hope a simple question. I am trying to learn the basic Objective-C compilation from the command line with clang. I understand that Xcode is the best solution for complex projects, and I plan to switch to it soon, but personally it seems to me that I understand the language better if I can compile it manually in the terminal, and for smaller introductory software projects I find it less hassle to compile in the terminal than launching a new project.
So the question is: how do I compile an Objective-C program that consists of several files (from the command line)? (I'm trying to run the fractions program from Chapter 7 of Kochan’s tutorial with the main.m and Fraction.m files, which are both #import "Fraction.h" and the Fraction.h file that imports the Foundation framework). To compile a single file, I use something like
clang -fobjc-arc main.m -o prog1
But if I type this and I want to include files other than main.m in the project, I get errors, including:
ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
If I try to add additional files to the command as arguments, for example
clang -fobjc-arc main.m Fraction.h Fraction.m -o prog1
then i get
clang: error: cannot specify -o when generating multiple output files
And if I remove the -o argument, for example
clang -fobjc-arc main.m Fraction.h Fraction.m
then I get a gigantic bunch of errors related to the underlying structure, ending up with a “fatal error: too many errors were emitted, stopping now.”
How do I do this and make it work? Or do I just need to suck it and use Xcode as soon as more than one file is involved?
Displaced hoser
source share