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 758531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:29:23+00:00 2026-05-14T15:29:23+00:00

Is there a way for GCC to produce a warning while linking libraries that

  • 0

Is there a way for GCC to produce a warning while linking libraries that contain classes with the same name? For example

Port.h

class Port {
public:
  std::string me();
};

Port.cpp

#include "Port.h"
std::string Port::me() { return "Port"; }

FakePort.h

class Port {
public:
  std::string me();
};

FakePort.cpp

#include "FakePort.h"
std::string Port::me() { return "FakePort"; }

main.cpp

#include "Port.h"

int main() {
  Port port;
  std::cout << "Hello world from " << port.me() << std::endl;
  return 0;
}

Building

# g++ -c -o Port.o Port.cpp
# ar rc Port.a Port.o
# g++ -c -o FakePort.o FakePort.cpp
# ar rc FakePort.a FakePort.o
# g++ -c -o main.o main.cpp
# g++ main.o Port.a FakePort.a
# ./a.out
  Hello world from Port

Change library order

# g++ main.o FakePort.a Port.a
# ./a.out
  Hello world from FakePort

According to this page:

If a symbol is defined in two different libraries gcc will use the first one it finds and ignore the second one unless the second one is included in an object file which gets included for some other reason.

So the above behavior make sense. Unfortunately I am inheriting a sizable code base that doesn’t make use of namespaces (and adding them isn’t feasible right now) and uses some generic class names throughout multiple libraries. I would like to automatically detect duplicate names at link time to make sure that the wrong copy of a class isn’t accidentally being instantiating. Something like:

# g++ -Wl,--warnLibraryDupSymbols main.o FakePort.a Port.a
  Warning: Duplicate symbol: Port

but I can’t find anything in the GCC linker options to do that. Is it possible to get GCC to automatically detect and report such cases?

  • 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-14T15:29:24+00:00Added an answer on May 14, 2026 at 3:29 pm

    The following might be worth a try (I honestly don’t know if it’ll do what you want):

    --whole-archive

    For each archive mentioned on the command line after the –whole-archive option, include every object file in the archive in the link, rather than searching the archive for the required object files. This is normally used to turn an archive file into a shared library, forcing every object to be included in the resulting shared library. This option may be used more than once.

    I haven’t tried it, but it sounds as if it’ll pull in all the items in a library as if they were object files. You’ll need to specify the option for each library.

    As Neil said, this won’t give you class-level conflicts, but if there are class members with the same signature, this might make the linker tell you.

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

Sidebar

Related Questions

Is there a way to download MinGW/MSYS2 with gcc, that is not localized? Localized
Is there a way to enable a hilighting scheme for gcc/g++ warning output? I'd
Is there any way to tell GCC to not initialize a particular global array
Is there a way to run the GCC preprocessor, but only for user-defined macros?
is there way how to get name ov event from Lambda expression like with
Is there a way to tell gcc to throw a SIGFPE or something similar
Is there a way to tell gcc to check argument number in a function
Is there any way to make gcc or clang warn about missing breaks in
On GCC Linux, is there a way I can add a file resource to
Is there a way with compiler flags to create the same memory layout of

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.