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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:15:41+00:00 2026-06-14T03:15:41+00:00

I am having trouble generating a shared object from a static library. While I

  • 0

I am having trouble generating a shared object from a static library. While I know there are other alternatives, I am now bothered (as opposed to stuck) by why this isn’t working and how to make it work.

Below is very simple source code I am using.

get_zero.c

#include "get_zero.h"

int
get_zero(void)
{
        return 0;
}

get_zero.h

int get_zero(void);

main.c

#include <stdio.h>
#include <string.h>

#include "get_zero.h"

int
main(void)
{
    return get_zero();
}

The goal is create two functionally equal applications using libget_zero_static and libget_zero_shared.

Here are my compilation/linking steps:

gcc -c -fPIC get_zero.c
ar cr libget_zero_static.a get_zero.o
gcc -shared -o libget_zero_shared.so -L. -Wl,--whole-archive -lget_zero_static -Wl,-no--whole-archive

And this is the error I get:

/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libc.a(init-first.o): relocation R_X86_64_32 against `_dl_starting_up' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libc.a(init-first.o): could not read symbols: Bad value
collect2: ld returned 1 exit status

This is on a 64-bit Ubuntu system.

I read about the whole-archive option here, and it seemed like this questions should have removed all of my road blocks.
How to create a shared object file from static library.

  • 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-14T03:15:42+00:00Added an answer on June 14, 2026 at 3:15 am

    It seems you need to specify the archive as an argument, not as a library. So make that libget_zero_static.a instead of -lget_zero_static. At least it works for me this way:

    gcc -shared -o libget_zero_shared.so \
    -Wl,--whole-archive                  \
    libget_zero_static.a                 \
    -Wl,--no-whole-archive
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble with Subsonic 3.0 generating an object for a table which
I'm having trouble generating a file reference in F# from a substring. I have
I am using Silverlight 4 and am having trouble correctly generating bitmaps from UIElements
I'm having trouble generating two independent random sequences using the rand and srand functions.
I am having some trouble generating a web form using fields specified in an
I'm having trouble with Project Euler's problem 12. My code is correctly generating the
I'm having trouble generating a timestamp in a Windows batch file, because I get
Problem: I am having trouble generating an xpath expression that selects a node in
I am having trouble generating a HTML/CSS layout. The best way to think of
I'm having trouble generating random numbers that do not follow a discrete uniform distribution.

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.