title: undefined reference to sync_fetch_and_add_4
body: <p>Whenever I try to use <strong>__sync_fetch_and_add</strong> with -m32 on a 64 bit machine, I get the following error, while it compiles fine with normal 64 bit. I am using gcc compiler 4.1.2. What can be the problem here and what is the solution?  </p>
  
  <pre><code>replication.cpp:(.text+0xb3b): undefined reference to `__sync_fetch_and_add_4'
  replication.cpp:(.text+0xb82): undefined reference to `__sync_fetch_and_add_4'
  replication.cpp:(.text+0xcc2): undefined reference to `__sync_fetch_and_add_4'
  /tmp/cc7u9FLV.o: In function `potential_barrier_leader(unsigned int, pthread_barrier_t*)':
  replication.cpp:(.text+0xd3f): undefined reference to `__sync_fetch_and_add_4'
  replication.cpp:(.text+0xd54): undefined reference to `__sync_fetch_and_add_4'
  /tmp/cc7u9FLV.o:replication.cpp:(.text+0xdb0): more undefined references to `__sync_fetch_and_add_4' follow
  collect2: ld returned 1 exit status
  make: *** [all] Error 1
  </code></pre>