title: Compiling results in error "undefined symbols for architecture i386"
body: <p>I've compiled the Box2D library in Xcode which has generated a static library file.</p>
  
  <p>I linked this library to mono touch but when I try to compile I get errors about undefined symbols in various source files.</p>
  
  <p>I've looked at the first few and they seem to be complaining about pointer initializations (i.e. using malloc/new), for example:</p>
  
  <pre><code>Undefined symbols for architecture i386:
    "std::terminate()", referenced from:
        b2BroadPhase::b2BroadPhase()in libBox2D.a(b2BroadPhase.o)
        b2BroadPhase::~b2BroadPhase()in libBox2D.a(b2BroadPhase.o)
        b2BroadPhase::~b2BroadPhase()in libBox2D.a(b2BroadPhase.o)
        b2BroadPhase::b2BroadPhase()in libBox2D.a(b2BroadPhase.o)
        b2Island::Solve(b2TimeStep const&amp;, b2Vec2 const&amp;, bool)in libBox2D.a(b2Island.o)
        b2World::b2World(b2Vec2 const&amp;, bool)in libBox2D.a(b2World.o)
        b2World::SolveTOI(b2Body*)     in libBox2D.a(b2World.o)
  </code></pre>
  
  <p>The b2BroadPhase constructor looks like so:</p>
  
  <pre><code>b2BroadPhase::b2BroadPhase()
  {
      m_proxyCount = 0;
  
      m_pairCapacity = 16;
      m_pairCount = 0;
      m_pairBuffer = (b2Pair*)b2Alloc(m_pairCapacity * sizeof(b2Pair));
  
      m_moveCapacity = 16;
      m_moveCount = 0;
      m_moveBuffer = (int32*)b2Alloc(m_moveCapacity * sizeof(int32));
  }
  </code></pre>
  
  <p>The b2Alloc function is simple:</p>
  
  <pre><code>void* b2Alloc(int32 size)
  {
      return malloc(size);
  }
  </code></pre>
  
  <p>And commenting out the two lines calling b2Alloc makes the error when the library is linked go away, though obviously that's not a solution to the problem.</p>
  
  <p>I've found other people have had similar problems but all their problems have been with Xcode compiling, I'm not sure how I could fix this issue in mono touch?</p>
  
  <p>edit: In response to Mark Bs answer I'd like to add I'm loading up the lib with the following command line:</p>
  
  <pre><code>-gcc_flags "-L${ProjectDir} -lBox2D -cxx -force_load
  ${ProjectDir}/libBox2D.a"
  </code></pre>
  
  <p>Which should mean that the lib is loaded up with C++ as per <a href="http://ios.xamarin.com/index.php?title=Documentation/Linking_Native_Libraries&amp;highlight=static%20library" rel="nofollow">this documentation</a></p>