LinuxQuestions.org
Visit Jeremy's Blog.
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 05-12-2009, 10:35 AM   #1
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Is it possible to convert .so into .a ?


Suppose I have .so file under Linux (i.e. a DLL) and I want to convert it into .a (static library) - is it possible ?

I've tried WEB search, and it shows how to do the opposite, i.e. how to convert .a -> .so , which is pretty trivial (ar -x ..., relink).

I mean "binary" conversion, i.e. not rebuilding/relinking from source, i.e. let's assume there is access only to .so file and not to sources.

Alternatively, directly obtaining a statically linked executable with .so would do, but not relying on .so at runtime.
 
Old 05-12-2009, 10:43 AM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
The ar command doesn't do anything to the internal content of any files it's putting into or taking out of an archive. So use ar with confidence to create libraries, make single copies of files that existed in libraries, and rename those single copies to your heart's content.
 
Old 05-12-2009, 10:48 AM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Original Poster
Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by wje_lq View Post
The ar command doesn't do anything to the internal content of any files it's putting into or taking out of an archive. So use ar with confidence to create libraries, make single copies of files that existed in libraries, and rename those single copies to your heart's content.
Have you ever tried 'ar' on .so files ?
 
Old 05-12-2009, 12:03 PM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by Sergei Steshenko View Post
Have you ever tried 'ar' on .so files ?
Good point. Although my original statement is correct, I'm afraid it isn't very helpful; sorry about that.

I've done some googling about your question (and I'm sure you did, too). I don't find anything very helpful.

If I were in your position and I had copious amounts of free time, I would look into the source for the linker, and see whether the building of a shared library removes information which would be necessary to work backwards to the original .a files from a .so file. If no such information is removed, I would write a quick and dirty utility to go in the direction you desire. If it is removed, you're out of luck.

In other words, I can't help you. Sorry. :(
 
Old 05-12-2009, 03:19 PM   #5
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

Rep: Reputation: 22
I've never heard about a possibility to do so. I also can't imagine it working since shared objects are some form of executable files, while static libs are collections of objects/functions, so the question would be if they are even able to have the necessary informations to recreate the object files.
Another things that question the plausibility to me is when you think about shared objects that for themselves have dependencies on other shared objects and those too, etc. ... would such a roundtrip make sense ?

I'm genuinely curious too though, so if anyone can give a definitive 'Yes' or 'No', please do so.
 
Old 05-12-2009, 04:19 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Original Poster
Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by fantas View Post
I've never heard about a possibility to do so. I also can't imagine it working since shared objects are some form of executable files, while static libs are collections of objects/functions, so the question would be if they are even able to have the necessary informations to recreate the object files.
Another things that question the plausibility to me is when you think about shared objects that for themselves have dependencies on other shared objects and those too, etc. ... would such a roundtrip make sense ?

I'm genuinely curious too though, so if anyone can give a definitive 'Yes' or 'No', please do so.
The item in bold is not quite correct WRT the thread.

For example,

Code:
objdump -d /lib/libz.so.1
happily works on my machine.

And remember, linker ('ld') easily gets satisfaction (== resolves symbols) both in case of .a and .so file, though in the latter case final binding occurs during runtime.

Also, .so files are bigger than the same .a file.

So, I think, .so files contains all the info needed to create a .a file plus more.

...

Maybe 'objcopy' can do the job in a number of passes - haven't tried 'objcopy' at all yet.
 
Old 05-12-2009, 04:46 PM   #7
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

Rep: Reputation: 22
Well isn't that more like a special case ? I was talking about straight dynamic libraries (ELF for example), which don't necessarily need to contain all symbol informations.
 
Old 05-12-2009, 05:01 PM   #8
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Original Poster
Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by fantas View Post
Well isn't that more like a special case ? I was talking about straight dynamic libraries (ELF for example), which don't necessarily need to contain all symbol informations.
Of course, if a file does not contain all symbol information, it can't be used for linking, but this is not what this thread is about.
 
Old 05-12-2009, 07:27 PM   #9
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

Rep: Reputation: 22
If a shared object doesn't have all symbols as info doesn't mean it's not linkable, so that's not correct to say I'm afraid. It would be kinda useless if it wasn't linkable, wouldn't it ?

Last edited by fantas; 05-12-2009 at 07:33 PM.
 
Old 11-28-2009, 09:24 AM   #10
steveneashcraft
LQ Newbie
 
Registered: Nov 2009
Posts: 1

Rep: Reputation: 0
Convert .so to .a

Has anyone figured out how to convert a .so (shared library) to a .a (static library)?
 
Old 11-28-2009, 10:55 AM   #11
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Original Poster
Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by steveneashcraft View Post
Has anyone figured out how to convert a .so (shared library) to a .a (static library)?
Try the 'objdump -d' idea, i.e. to disassemble and then to recompile into .o files, then to create static library.

I haven't tried it myself, but seems like a good start.
 
  


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
Another Convert blade1950 LinuxQuestions.org Member Intro 1 03-25-2009 06:40 PM
Another convert Jareb LinuxQuestions.org Member Intro 1 03-22-2009 04:11 AM
Trying to Convert lovelybug LinuxQuestions.org Member Intro 2 01-04-2009 03:28 PM
Am I a convert?? SlackerLX LinuxQuestions.org Member Success Stories 22 01-12-2005 02:01 PM
Trying to Convert GATTACA Slackware 3 11-23-2003 12:40 PM

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

All times are GMT -5. The time now is 09:19 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