title: Compilation error "Undefined symbols" on osx
body: <p>I am trying out a very simple cpp program on osx just to get myself familiar with the osx platform, so I am very surprised to encounter any error message.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt; 
  using namespace std; 
  int main() { 
    cout &lt;&lt; "Hello, world!" &lt;&lt; endl; 
    return 0; 
  }
  </code></pre>
  
  <p>I compile it by running</p>
  
  <pre><code>gcc -Wall hello.cpp -o hello
  </code></pre>
  
  <p>Then I get this 'undefined symbols' message:</p>
  
  <pre><code>Undefined symbols:
    "std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, char const*)", referenced from:
        _main in ccA9oElQ.o
    "std::ios_base::Init::Init()", referenced from:
        __static_initialization_and_destruction_0(int, int)in ccA9oElQ.o
    "std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::size() const", referenced from:
        std::__verify_grouping(char const*, unsigned long, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)in ccA9oElQ.o
    "std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::operator[](unsigned long) const", referenced from:
        std::__verify_grouping(char const*, unsigned long, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)in ccA9oElQ.o
        std::__verify_grouping(char const*, unsigned long, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)in ccA9oElQ.o
        std::__verify_grouping(char const*, unsigned long, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)in ccA9oElQ.o
    "___gxx_personality_v0", referenced from:
        std::__verify_grouping(char const*, unsigned long, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)in ccA9oElQ.o
        _main in ccA9oElQ.o
        ___tcf_0 in ccA9oElQ.o
        unsigned long const&amp; std::min&lt;unsigned long&gt;(unsigned long const&amp;, unsigned long const&amp;)in ccA9oElQ.o
        __static_initialization_and_destruction_0(int, int)in ccA9oElQ.o
        global constructors keyed to mainin ccA9oElQ.o
        CIE in ccA9oElQ.o
    "std::ios_base::Init::~Init()", referenced from:
        ___tcf_0 in ccA9oElQ.o
    "std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::endl&lt;char, std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)", referenced from:
        _main in ccA9oElQ.o
    "std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;::operator&lt;&lt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; (*)(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;))", referenced from:
        _main in ccA9oElQ.o
    "std::cout", referenced from:
        _main in ccA9oElQ.o
  ld: symbol(s) not found
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>I do not know if it is related: I have both xcode 3 and xcode 4 installed on my MBP</p>
  
  <p>Here is the version information:</p>
  
  <pre><code>$ gcc -v
  Using built-in specs.
  Target: i686-apple-darwin10
  Configured with: /var/tmp/gcc/gcc-5666.3~6/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
  Thread model: posix
  gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
  </code></pre>
  
  <p>System information</p>
  
  <pre><code>$ uname -a
  Darwin mbp002.local 10.7.0 Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386 i386
  </code></pre>