Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-27-2007, 11:34 AM   #1
LQ Newbie
Registered: Jul 2007
Posts: 1

Rep: Reputation: 0
Making a static library from a given shared library


does anyone know how to make a static library, say libA.a, of a given shared library ? Is that possible at all? (needless to mention that I don't have the sources of

Related to that question is how to merge two shared libraries and so that all references between libA and libB are internally resolved. That means later on, when linking something to, no dependencies to nor to shall persist.

Obviously the naive approaches
 ar -cr libA.a
 ld -shared -soname -o
do not solve the problem. I browsed the several man pages in the binutils package but could not find the answer there. Maybe objcopy could do the trick?

Hope someone can help me here.

Old 07-27-2007, 04:07 PM   #2
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Static libraries aren't linked, whereas shared libraries are. You could make a shared library from a static one, but I don't believe you can go the other way. Since a static library is just an archive of object files, you would have to find a way to "unlink" the shared library. Additionally, some of the source files may have specified visibility attributes for functions or data which can prevent symbols from being exported, essentially making them unavailable.

I've tried incrementally linking an object file to a shared library to make a static library, but that hasn't worked for me. Do you have the source code for the shared library? You could tune the auto-tool files to force it to make a static library.

edit: Just noticed you don't have the sources. For your second question, have you tried using -rpath and -rpath-link?

Last edited by ta0kira; 07-27-2007 at 04:11 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
shared to static library ofada Programming 2 07-08-2009 11:54 AM
LINUX - linking archive (static library) with shared (dynamic) library gurkama Programming 5 03-04-2007 11:11 PM
Hiding global symbols in a shared/static library jineshkj Programming 16 08-30-2006 12:45 AM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM
NEWBIE : Please how to distribute a shared or static library with a rpm simus Linux - General 0 02-18-2004 10:31 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:11 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration