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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:25:26+00:00 2026-05-17T02:25:26+00:00

I have the following problem : several object files a1.o, a2.o, a3.o, … an

  • 0

I have the following problem :

  • several object files a1.o, a2.o, a3.o, …
  • an archive libxxxx.a.
    The archive libxxxx.a only contains object files : b1.o, b2.o etc…

I would like to create a shared library (.so) from all the object files.

Problem : If I use :

g++ -shared libxxxx.a a1.o a2.o ... -o libnew.so

g++ does understand that I want to link with the static library libxxxx.a and does not include all the symbols of the archive.

A simple workaround is to first expand the archive using ar -x and then create the lib but it’s not really “elegant”.

There must be a simple command to force g++ to include the whole archive in the .so but I can’t find it.

Thanks for your help.

  • 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-17T02:25:27+00:00Added an answer on May 17, 2026 at 2:25 am

    From man ld:

    –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.

    Two notes when using this option from gcc: First, gcc doesn’t know about this option, so you have to use -Wl,-whole-archive.
    Second, don’t forget to use -Wl,-no-whole-archive after your list of archives, because gcc will add its own list of archives to your
    link and you may not want this flag to affect those as well.

    Example:

    g++ -shared -o yourlib a.o. b.o. c.o -Wl,-whole-archive libstatic.a -Wl,-no-whole-archive
    

    Note also that in your example you first put static library, then the object files – in this case the symbols used in the object files and defined in static library will not be found unless you use --whole-archive linker option. If you want to include just the needed symbols from the static library, you need to put it after the object files.

    g++ -o your_app a.o b.o c.o -lyour_static_lib
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working for a while on a project with the following components:
I have a DataGrid , which is bound to a DataTable object. The user
I have successfully created my first django project. I have two apps in my
I have an ASP.NET repository site running on IIS6.0 and I have an issue
I have recently been doing a security code review for my company and using
I am facing a problem of design time support best practices. I am using
I've been experimenting with the audio and local storage features of html5 of late
I'm about to begin designing the architecture of a personal project that has the
So I've been working recently on a script to obfuscate client-side code for protecting
I am currently developing an application in which I want to display a UserControl

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.