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

  • Home
  • SEARCH
  • 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 3624204
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:28:43+00:00 2026-05-18T23:28:43+00:00

It appears GCC linker doesn’t care for one variable being defined in two files.

  • 0

It appears GCC linker doesn’t care for one variable being defined in two files. I suspect this is the cause of trouble a 3rd party library is causing us.

Take this:

File a.cpp contains:

 int foo;
 //do things with it.

File b.cpp contains:

 int foo;
 //do other things with it.

File c.cpp contains:

 extern int foo;
 //do other things with it.

They are all compiled by gcc to .o files, then linked as shared object.

 gcc -fPIC -c a.cpp
 gcc -fPIC -c b.cpp
 gcc -fPIC -c c.cpp
 ld *.o -shared  -soname,mylib -o mylib

The linker doesn’t complain at all, but the resulting binary misbehaves. We suspect there are at least a few conflicts of this kind and would like to locate them. What kind of linker options would let us detect them?

(interestingly, if the variables are initialized (int foo=0) in both files, it produces an error).

  • 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. Editorial Team
    Editorial Team
    2026-05-18T23:28:44+00:00Added an answer on May 18, 2026 at 11:28 pm

    It seems compiler option -fno-common forces all the variables to be initialized, so it triggers errors upon linking.

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

Sidebar

Related Questions

How do I get rid of this linker warning that appears every time I
It appears the Python signal module doesn't have anything similar to the sighold and
I know how to compile C and C++ Source files using GCC and CC
I cannot figure out why this segment gives unresolved overloaded function error (gcc version
I have a weird condition that only appears on gcc -O0 -g output, not
I get this message when compiling C++ on gcc 4.3 error: ‘NULL’ was not
I'm having a hard-time debugging a local variable. I'm running gcc 4.2 , XCode
It appears that Xcode4 doesn't include PPC as a build option anymore. When using
NULL appears to be zero in my GCC test programs, but wikipedia says that
(Running MingW on 64-bit Windows 7 and the GCC on Kubuntu) This may possibly

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.