title: How do you compile and run an objective-c file outside Xcode?
body: <p>I have tried to run multiple HelloWorld files written in Xcode using <code>gcc</code> in terminal. For the sake of conciseness this is one example from <em>TutorialsPoint</em>, in a standalone file called <code>myStandaloneHelloWorld.m</code>:</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  @interface SampleClass:NSObject
  - (void)sampleMethod;
  @end
  
  @implementation SampleClass
  
  - (void)sampleMethod{
      NSLog(@"Hello, World! \n");
  }
  
  @end
  
  int main()
  {
      /* my first program in Objective-C */
      SampleClass *sampleClass = [[SampleClass alloc]init];
      [sampleClass sampleMethod];
      return 0;
  }
  </code></pre>
  
  <p>Which is compiled in Xcode but when <code>gcc myStandaloneHelloWorld.m</code> is run in terminal, the following list of errors is produced:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "_NSLog", referenced from:
        -[SampleClass sampleMethod] in myStandaloneHelloWorld-0af75e.o
    "_OBJC_CLASS_$_NSObject", referenced from:
        _OBJC_CLASS_$_SampleClass in myStandaloneHelloWorld-0af75e.o
    "_OBJC_METACLASS_$_NSObject", referenced from:
        _OBJC_METACLASS_$_SampleClass in myStandaloneHelloWorld-0af75e.o
    "___CFConstantStringClassReference", referenced from:
        CFString in myStandaloneHelloWorld-0af75e.o
    "__objc_empty_cache", referenced from:
        _OBJC_METACLASS_$_SampleClass in myStandaloneHelloWorld-0af75e.o
        _OBJC_CLASS_$_SampleClass in myStandaloneHelloWorld-0af75e.o
    "_objc_msgSend", referenced from:
        _main in myStandaloneHelloWorld-0af75e.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>I know there are other frameworks and syntaxes (for example an Xcode command line tool with very different syntax runs within Xcode), but what is wrong with this syntax run in terminal?</p>