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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:26:51+00:00 2026-06-07T13:26:51+00:00

I need to define module name somehow for each of my static libraries and

  • 0

I need to define module name somehow for each of my static libraries and a project that uses them. I cannot to do this simply as:

std::string const module_name = "my module";

because I need this value during static members initialization. Since static data initialization order is not defined, my module_name variable can be still uninitialized while I’m trying to use it.

To resolve this problem I defined

inline std::string const& module_name() 
{
    static std::string const name = "my module";
    return name;
}

for each module. But this doesn’t work because all module_name() calls was resolved to use implementation from the parent module (module_name() always returns the name of the parent executable project). And I don’t understand why. I hoped that since this inline function is defined and used in a static library, actual module name should be captured. Is it because this function wasn’t inlined by compiler?

Is there any recommended way to resolve this problem?

compiler: VC++10 and gcc, tested on VC++10

  • 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-06-07T13:26:53+00:00Added an answer on June 7, 2026 at 1:26 pm

    An entity with external linkage can only have one definition in a program, so it’s not surprising you can’t have multiple definitions of the same function in one program.

    It’s not to do with inlining, what happens is the linker sees multiple definitions of the same symbol (which often happens with template instantiations and inline functions, and other symbols when using dynamic libs) and picks one definition to use.

    To make each libary have a separate definition you need them to have internal linkage, which can be done by making the function static or putting it in an unnamed namespace, or using platform-specific methods such as __dllimport or __attribute((visibility("hidden"))) to tell the compiler the symbol is private to the shared library and should not be exported (and therefore won’t be replaced by another definition of the same symbol.)

    Alternatively, just put each module in its own namespace and put the function in that namespace, then each function is different and they won’t interfere.

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

Sidebar

Related Questions

I need to define the constant in the module that use the method from
I need to define a Wix file component that may not exist in certain
I need to define an appender for log4net in a way that I get
I need to define some constant strings that will be used only by one
Although appengine already is schema-less, there still need to define the entities that needed
So I'm trying to write a kernel module that uses the linux/timer.h file. I
I need to define multiple modules in the same file. I would like to
I need to define a Structuring Element of a mask size 30 by 105
I need to define an <img>'s src attribute in CSS. Is there a way
Why is there a need to define a new method in RESTful controller, follow

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.