title: Link error when compiling gcc atomic operation in 32-bit mode
body: <p>I have the following program:</p>
  
  <pre><code>~/test&gt; cat test.cc
  int main()
  {
    int i = 3;
    int j = __sync_add_and_fetch(&amp;i, 1);
    return 0;
  }
  </code></pre>
  
  <p>I'm compiling this program using GCC 4.2.2 on Linux running on a multi-cpu 64-bit Intel machine:</p>
  
  <pre><code>~/test&gt; uname --all
  Linux doom 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:56:44 EST 2007 x86_64 x86_64 x86_64 GNU/Linux
  </code></pre>
  
  <p>When I compile the program in 64-bit mode, it compiles and links fine:</p>
  
  <pre><code>~/test&gt; /share/tools/gcc-4.2.2/bin/g++ test.cc
  ~/test&gt;
  </code></pre>
  
  <p>When I compile it in 32-bit mode, I get the following error:</p>
  
  <pre><code>~/test&gt; /share/tools/gcc-4.2.2/bin/g++ -m32 test.cc
  /tmp/ccEVHGkB.o(.text+0x27): In function `main':
  : undefined reference to `__sync_add_and_fetch_4'
  collect2: ld returned 1 exit status
  ~/test&gt;
  </code></pre>
  
  <p>Although I will never actually run on a 32-bit processor, I do need a 32-bit executable so I can link with some 32-bit libraries.</p>
  
  <p>My 2 questions are:</p>
  
  <ol>
  <li><p>Why do I get a link error when I compile in 32-bit mode?</p></li>
  <li><p>Is there some way to get the program to compile and link, while still being able to link with a 32-bit library?</p></li>
  </ol>