LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-25-2006, 03:27 PM   #1
gurkama
LQ Newbie
 
Registered: Jul 2006
Posts: 5

Rep: Reputation: 0
LINUX - linking archive (static library) with shared (dynamic) library


Hi all,

I want to create an archive from a bunch of object files that should be linked with an existing shared library. Meaning that I would like to link the archive with a shared library.

Can it be done? If so - how can I do that?

I'm working with GNU Linux 2.6.

Thanks
 
Old 07-25-2006, 03:30 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
The object files themselves would need to be linked against the shared library, AFAIK.
 
Old 07-25-2006, 03:45 PM   #3
gurkama
LQ Newbie
 
Registered: Jul 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks Matir for your quick response.

However, I still don't get what you meant:
When creating the objects there's no linkage - I only compile the c files into object files using implicit rule. How can I link the objects with a shared library as you kindly suggested?

Thanks
 
Old 07-25-2006, 05:00 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
I believe you'd need to use:
Code:
gcc -shared -Wl,-soname,LIBNAME -o LIBNAME OBJFILES -lOTHERLIBRARY
 
Old 09-01-2006, 02:48 PM   #5
twist
LQ Newbie
 
Registered: Sep 2006
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by Matir
I believe you'd need to use:
Code:
gcc -shared -Wl,-soname,LIBNAME -o LIBNAME OBJFILES -lOTHERLIBRARY
I'm trying to build a .so from a .a like so:

Code:
ar r foo.a foo.o
gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0 foo.a
A .so is produced but linking against it results in undefined references to globals in foo.o. However just using the .o ...

Code:
gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0 foo.o
works fine and all global symbols in foo.o are found.

What do I need to do to get the linux linker to see globals in foo.a? I tried a version script but either I got it wrong or I'm missing something.

Ultimately I have two goals:

1) produce a .so from a .a
2) control which symbols are visible (i.e. global) in the .so

FWIW, I'm coming from an AIX background where .a's work in this context and symbol visibilty can be controlled via .exp files.

Any help would greatly be appreciated.

Thanks.
 
Old 03-04-2007, 11:11 PM   #6
negiliblek
LQ Newbie
 
Registered: Jan 2006
Posts: 2

Rep: Reputation: 0
script to change static .a to a shared .so

can't say I know exactly what you're talking about but here is a site where the script below came from homes.esat.kuleuven.be/~gcc/shared_libraries.html

(Note this site also discusses stripping unwanted symbols out)

# Converting a static to a shared library:

#! /usr/bin/ksh -p
#
# Makes a shared library from a static one
#
static_library=$1; shared_library=$2
ld -shared -s -h /freeware/gcc/linux-i386/lib/{shared_library} -o ${shared_library:-${static_library%%a}so} -whole-archive ${static_library}


I'm testing this script right now on an archive libmpeg3.a

Quote:
Originally Posted by twist
I'm trying to build a .so from a .a like so:

Code:
ar r foo.a foo.o
gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0 foo.a
A .so is produced but linking against it results in undefined references to globals in foo.o. However just using the .o ...

Code:
gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0 foo.o
works fine and all global symbols in foo.o are found.

What do I need to do to get the linux linker to see globals in foo.a? I tried a version script but either I got it wrong or I'm missing something.

Ultimately I have two goals:

1) produce a .so from a .a
2) control which symbols are visible (i.e. global) in the .so

FWIW, I'm coming from an AIX background where .a's work in this context and symbol visibilty can be controlled via .exp files.

Any help would greatly be appreciated.

Thanks.
 
  


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
Convert static library (Filename.a) to dynamic shared object (filename.so) afx2029 Linux - Software 4 08-17-2007 06:07 AM
Linking to a static library gives unresolved symbol enemorales Programming 3 01-24-2006 08:19 AM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM
static linking to c library lantern Programming 1 04-19-2004 08:58 AM
Linking a platform independent shared library rozeboom Programming 3 11-18-2003 02:10 PM

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

All times are GMT -5. The time now is 10:16 AM.

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