LinuxQuestions.org
Visit Jeremy's Blog.
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-01-2007, 09:01 AM   #1
jeevanladhe
LQ Newbie
 
Registered: May 2007
Posts: 1

Rep: Reputation: 0
How to create shared objects and how are they useful


hi all,
i want to create a .so of myfile.c,
then dynamically while program is running,
i want this .so to be linked or unlinked as per needs.
Is there any way do to this.
Please help me as soon as possible.
thanks in advance.
 
Old 05-01-2007, 12:59 PM   #2
dasy2k1
Member
 
Registered: Oct 2005
Location: 127.0.0.1
Distribution: Ubuntu 12.04 X86_64
Posts: 958

Rep: Reputation: 35
this forum is primarrly for saying hi,
thsi woudl be better suited in the programming forum
 
Old 05-01-2007, 02:09 PM   #3
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,176
Blog Entries: 4

Rep: Reputation: 430Reputation: 430Reputation: 430Reputation: 430Reputation: 430
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 05-01-2007, 02:16 PM   #4
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
Look at
http://tldp.org/HOWTO/Program-Library-HOWTO/

Especially the section on dlopen and dlclose
 
Old 05-01-2007, 02:41 PM   #5
haxpor
Member
 
Registered: Dec 2006
Distribution: Ubuntu 9.10
Posts: 86

Rep: Reputation: 15
Is the question also included 'how to create dynamic link library'? If so, this is answer.
To create share library or dynamic link library do as follow.
I also include description taking from 'man gcc' for time-saving too.

Create ddl:
Code:
#gcc -c -fPIC mydev.c -o mydev.o
#gcc -shared libmydev.so mydev.o
Create executable file (linking with ddl)
Code:
#gcc mynewdev.c libmydev.so
Then when you take your program to run on other machines make sure you copy *.so file to /lib/ or /usr/lib too.

Ref
Quote:
-fPIC
If supported for the target machine, emit position-independent
code, suitable for dynamic linking and avoiding any limit on the
size of the global offset table. This option makes a difference
on the m68k and the SPARC.

Position-independent code requires special support, and therefore
works only on certain machines.
I think you already know how to create static library but I will included to this post for another may find it useful.

Create static link library:
Code:
#gcc -c mydev.c -o mydev.o
#ar rcs libmydev.a mydev.o
Create executable file (linking with static):
Code:
#gcc -static mynewdev.c -lmydev
 
  


Reply


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
How to see of which objects files is particular shared library made of? halturata Programming 4 04-12-2006 02:35 AM
Dynamically sized objects in shared memory jtshaw Programming 2 03-16-2005 11:12 AM
any links on linking, loading shared libraries, shared objects. etc? ananthbv Programming 0 02-03-2005 08:47 AM
Creating Shared objects Anup Kumar Programming 1 09-12-2004 12:45 AM
g++ missing shared objects pinguwin Linux - Software 0 05-27-2004 09:38 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration