LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

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


Hi,

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

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

Obviously the naive approaches
Code:
 ar -cr libA.a libA.so
and
Code:
 ld -shared -soname libAB.so -o libab.so libA.so libB.so
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.

Best,
vro
 
Old 07-27-2007, 04:07 PM   #2
ta0kira
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.
ta0kira

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.
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:23 PM.

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