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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:56:00+00:00 2026-05-17T14:56:00+00:00

Suppose I want to version the libs in binaries made. For static libs, I

  • 0

Suppose I want to version the libs in binaries made. For static libs, I thought this approach would work but it does not:

LibInfo.h – Base class for all libinfo classes. Registers an object in gvLibInfo vector when a child is constructed.

#ifndef IFACE_H
#define IFACE_H

#include <vector>

class LibInfo;
extern std::vector<LibInfo*> gvLibInfo;

class LibInfo
{
    public:
        virtual int getversion() = 0;
        void reglib()
        {
            gvLibInfo.push_back(this);
        }

        LibInfo()
        {
            reglib();
        }
        virtual ~LibInfo()
        {}
};


#endif

Lib1.h – Derived from LibInfo and creates an object l1. Lib2.h is the same except getversion returns 2.

#ifndef LIB1_H
#define LIB1_H

#include "LibInfo.h"

class Lib1 : public LibInfo
{
    public:
        int getversion()
        {
            return 1;
        }

    private:
};

Lib1 l1;

#endif

main.cpp

#include "Lib1.h"
#include <iostream>
using namespace std;

vector<LibInfo*> gvLibInfo;

int main()
{       
    for(vector<LibInfo*>::iterator it = gvLibInfo.begin(); it != gvLibInfo.end(); it++)
    {       
        cout << (*it)->getversion() << endl;
    }

    return 0;
}

Compiling –

g++ -c Lib1.h -o Lib1.o
g++ -c Lib2.h -o Lib2.o
ar cr lib.a Lib1.o Lib2.o
g++ main.cpp -o app -L/home/duminda/statictest/lib.a

When I run, nothing happens. I thought this maybe due to one of several reasons:

  1. At the time Lib1 l1 is made, gvLibInfo has not been constructed.
  2. I saw somewhere that the linker will remove any unused variables from a static lib. However, when I run on the binary nm it shows up this :

0000000000603280 B gvLibInfo

0000000000603270 B l1

0000000000603278 B l2

I guess l1 & l2(The corresponding object of class Lib2 are there but what does that ‘B’ flag mean?
3. Something else I don’t know.

  • 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-17T14:56:00+00:00Added an answer on May 17, 2026 at 2:56 pm

    The first answer to this question propose to use the –whole-archive flag.
    The main difference is, instead of referring to an external object, the library refers
    to an external function.

    Linking does not occur with -L, but with -l, i.e. it should be :

    -L/path/to/libdir -lname
    

    If your library is :

    /path/to/libdir/libname.a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Of course most languages have library functions for this, but suppose I want to
Suppose you want to make an async request in JavaScript, but you want to
Suppose I want to open a file in an existing Emacs session using su
Suppose I want to implement a reasonably efficient 'keyword recognition algorithm', that is first
Suppose I want to create a set of observers based on type. That is
Suppose I want to count the lines of code in a project. If all
Suppose you want to add an extra layer of credentials on top of a
What's the best way retrieve complex queries from a REST service? Suppose I want
Suppose I have one long long int and want to take its bits and
Suppose that you have two huge files (several GB) that you want to concatenate

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.