Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 48877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:20:56+00:00 2026-05-10T16:20:56+00:00

I have the following program: ~/test> cat test.cc int main() { int i =

  • 0

I have the following program:

~/test> cat test.cc int main() {   int i = 3;   int j = __sync_add_and_fetch(&i, 1);   return 0; } 

I’m compiling this program using GCC 4.2.2 on Linux running on a multi-cpu 64-bit Intel machine:

~/test> 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 

When I compile the program in 64-bit mode, it compiles and links fine:

~/test> /share/tools/gcc-4.2.2/bin/g++ test.cc ~/test> 

When I compile it in 32-bit mode, I get the following error:

~/test> /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> 

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.

My 2 questions are:

  1. Why do I get a link error when I compile in 32-bit mode?

  2. Is there some way to get the program to compile and link, while still being able to link with a 32-bit library?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T16:20:57+00:00Added an answer on May 10, 2026 at 4:20 pm

    From the GCC page on Atomic Builtins:

    Not all operations are supported by all target processors. If a particular operation cannot be implemented on the target processor, a warning will be generated and a call an external function will be generated. The external function will carry the same name as the builtin, with an additional suffix `_n’ where n is the size of the data type.

    Judging from your compiler output, which refers to __sync_add_and_fetch_4, this is what’s happening. For some reason, GCC is not generating the external function properly.

    This is likely why you’re only getting an error in 32-bit mode – when compiling for 64-bit mode, it compiles for your processor more closely. When compiling for 32-bit, it may well be using a generic arch (i386, for example) which does not natively support those features. Try specifying a specific architecture for your chip family (Xeon, Core 2, etc.) via -mcpu and see if that works.

    If not, you’ll have to figure out why GCC isn’t including the appropriate function that it should be generating.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 104k
  • Answers 104k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Create your procedure. Drag it to the data context designer.… May 11, 2026 at 8:36 pm
  • Editorial Team
    Editorial Team added an answer Convention over Configuration (aka Coding by convention) is a software… May 11, 2026 at 8:36 pm
  • Editorial Team
    Editorial Team added an answer reg [n-1:0] Y_compl; always @( Z, Y, X, carryin )… May 11, 2026 at 8:36 pm

Related Questions

The question is related to the answer to Unable to install Python without sudo
I have the following in a program (written in VB.NET): Imports Microsoft.Office.Interop.Excel Public Class
I have the following code class Program { static void Main(string[] args) { List<A>
I have the following in a program (part of a much larger function, but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.