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

  • Home
  • SEARCH
  • 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 6939253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:35:56+00:00 2026-05-27T12:35:56+00:00

Let’s say I want to create a dynamic library dynamic.so , but my code

  • 0

Let’s say I want to create a dynamic library dynamic.so, but my code references a function that exists in some other, static library static.a. Naturally, if I compile and link with g++ and the -sharedoption, dynamic.so will expect the referenced function to be implemented in some other dynamic library that I would have to link at runtime together with dynamic.so. In other words, it will be happy as long as I do -l static (modulo syntax).

But since that other library is actually a static one, I cannot do that. Let’s assume I can not link the static library at compile time of my main program either, but I’m forced to only use dynamic libraries. So what I really want is to include the compiled code off the referenced function from static.a in dynamic.so.

This answer to a related question suggests using the --whole-archive option to include static.a in dynamic.so. However, in my case, static.a is huge. And I really don’t need all of it, I only need that one function definition.

This answer to another question explains that linking to a static library at compile time means that only the code that is actually referenced gets included in the binary. Well, this is exactly what I would like to do for my single function reference! I don’t really want the whole static archive in there.

But how can I achieve that? How can I include just the required parts of static.a in dynamic.so?

  • 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-27T12:35:57+00:00Added an answer on May 27, 2026 at 12:35 pm

    You don’t need --whole-archive: just link your dynamic.so like this:

    gcc -shared -fPIC -o dynamic.so $(OBJS) -lstatic
    

    This will pull into dynamic.so anything the linker needs from libstatic.a. See this explanation to understand why that is.

    One problem might be that your libstatic.a is compiled without -fPIC. On 32-bit x86/Linux, that would still work (though your library will not be saving you much RAM if multiple processes are using it). On x86_64, linking non-fPIC code into a shared library can’t work, so you’ll have to rebuild it with -fPIC.

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

Sidebar

Related Questions

Let's say I want to write a function that validates an email address with
Let's say there is a graph and some set of functions like: create-node ::
Let's say you have a class library project that has any number of supplemental
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's say i have this block of code, <div id=id1> This is some text
Let's say you create a wizard in an HTML form. One button goes back,
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have a drive such as C:\ , and I want to
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,

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.