title: Boost.asio compilation problem: undefined reference to `__sync_add_and_fetch_8
body: <p>Hey guys,
  This could be a noob question, but I really can't find any useful solution through Google.
  I'm testing a hello world with boost.asio, the program is quite simple:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/date_time/posix_time/posix_time.hpp&gt;
  int main()
  {
      boost::asio::io_service io;
      boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
      t.wait();
      std::cout &lt;&lt; "Hello, world!\n";
      return 0;
  }
  </code></pre>
  
  <p>I passed the compilation and run well on my <strong>Intel Pentium PC (Ubuntu 10.10, gcc 4.4.5, Boost 1.46.0)</strong>. The command line I used was</p>
  
  <blockquote>
    <p>g++ -o a a.cpp -I /Boost-Include-Path/ -L /Boost-lib-Path/ -lboost_system</p>
  </blockquote>
  
  <p>But when I compile the same code on another machine(which is a big one, I'll explain it later), it can't pass the compilation and gives such errors:</p>
  
  <hr>
  
  <blockquote>
    <p>/tmp/ccOZxZBX.o: In function <code>boost::asio::detail::gcc_sync_fenced_block::gcc_sync_fenced_block()': a.cpp:(.text._ZN5boost4asio6detail21gcc_sync_fenced_blockC1Ev[boost::asio::detail::gcc_sync_fenced_block::gcc_sync_fenced_block()]+0x4c): undefined reference to</code>__sync_lock_test_and_set_4' /tmp/ccOZxZBX.o: In function <code>boost::detail::atomic_count::operator++()': a.cpp:(.text._ZN5boost6detail12atomic_countppEv[boost::detail::atomic_count::operator++()]+0x30): undefined reference to</code>__sync_add_and_fetch_8' /tmp/ccOZxZBX.o: In function <code>boost::detail::atomic_count::operator--()': a.cpp:(.text._ZN5boost6detail12atomic_countmmEv[boost::detail::atomic_count::operator--()]+0x30): undefined reference to</code>__sync_add_and_fetch_8' /tmp/ccOZxZBX.o: In function <code>boost::detail::atomic_count::operator long() const': a.cpp:(.text._ZNK5boost6detail12atomic_countcvlEv[boost::detail::atomic_count::operator long() const]+0x30): undefined reference to</code>__sync_fetch_and_add_8'</p>
  </blockquote>
  
  <hr>
  
  <p>The machine I used was a SiCortex SC5832,which use MIPS64 instruction set processors, OS is changed CentoOS. Gcc 4.2.3, Boost1.46.0. Is it possible that there are problems about the compatibility of the MIPS? I added -mips64 option, but it still give the same errors.
  I know this environment could not be very usual, but I think some people who are using similar big machines may face the same problem.</p>
  
  <p>Any help would be appreciated. By the way, I don't have sudo permission.</p>
  
  <p>Thanks,
  Tony</p>