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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:29:13+00:00 2026-06-09T15:29:13+00:00

I am creating a template-only C++ library. However, I’d like to provide an ’empty’

  • 0

I am creating a template-only C++ library. However, I’d like to provide an ’empty’ shared library as well, so that through controlling SONAME I would be able to enforce rebuilds of the template consumers whenever the templates change in a way resulting in instantiated template ABI incompatibility.

Sadly, if a particular user has -Wl,--as-needed in his LDFLAGS, the linker is going to remove my shared library from NEEDED because the compiled executable is not requesting any symbols from it. How can I ensure that the program will always be linked against my library, preferably not introducing unnecessary dummy function calls (or if I have to, making them least burdening)?

Edit: as a note, the particular template class provides static methods, and usually only those static methods are used. Thus, it is not a good idea to rely on anything put in the constructor, and I’d really like to avoid burdening all the methods with some kind of enforcement.


Inspired by @EmployedRussian, I achieved:

extern int dummy;

namespace
{
    struct G
    {
        inline G()
        {
            dummy = 0;
        }
    };

    static const G g;
}

But sadly, that performs the assignment once for every unit including the header file.

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

    However, I’d like to provide an ’empty’ shared library as well, so that through controlling SONAME I would be able to enforce rebuilds of the template consumers whenever the templates change in a way resulting in instantiated template ABI incompatibility.

    This will force an error at runtime.

    You can trivially achieve the same result (runtime error) without using SONAME. In one of your template headers, put in a global object that will at runime

    1. Take address of or call libmysolib_version_<N>, or
    2. Do dlopen(libmysolib.so, ...) and dlsym("libmysolib_version_<N>", ...)

    Then just keep incrementing N every time you break the ABI.

    preferably not introducing unnecessary dummy function calls

    Taking address of libmysolib_version_<N> does not call a function; it just forces the runtime linker to find that symbol once (at startup). You may though run afoul of the linker garbage collection.

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

Sidebar

Related Questions

I'm creating a new class that inherits queue from the STL library. The only
I'd like to create a ReSharper template that can only be used within comments
I am creating my own custom T4 Template that integrates with an ADO.NET Entity
I am creating a Multi project Template The problem is that when I run
I can apply a template to a subsite when creating it, however, on the
I am creating an attribute that I will use to provide additional information about
WordPress 3.2.1 I'm creating separate page templates, however, there are some page templates that
I'm creating an app where user needs to login first and only after that
I have a KnockoutJS template that looks something like this: <div data-bind=template: {name: 'testTemplate',
Problem Statement: I'm creating a template for multi tiered complicated calculations in MS Excel

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.