title: Undefined symbols for architecture x86_64: Which architecture should I use?
body: <p>I'm trying to do some really simple stuff in C++, but I can't find any information on how to tackle this. Even the book I have just says "Just compile and run the program".</p>
  
  <p><strong>test.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt; 
  using namespace std;
  
  int main() 
  { 
      cout &lt;&lt; "Never fear, C++ is here!"; 
      return 0;
  }
  </code></pre>
  
  <p>The compiler says:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "std::cout", referenced from:
        _main in ccVfJHGs.o
    "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 ccVfJHGs.o
    "std::ios_base::Init::Init()", referenced from:
        __static_initialization_and_destruction_0(int, int)in ccVfJHGs.o
    "std::ios_base::Init::~Init()", referenced from:
        ___tcf_0 in ccVfJHGs.o
  ld: symbol(s) not found for architecture x86_64
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>I tried compiling with flags like <code>-arch i386</code> and <code>-m32</code> but it always says it's the wrong architecture. Which one should I use?</p>
  
  <p>I'm doing this on a Mac but not using XCode, just gcc.</p>