Latest LQ Deal: Linux Power User Bundle
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 05-01-2007, 08:01 AM   #1
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, 11:59 AM   #2
Registered: Oct 2005
Distribution: Ubuntu 12.04 X86_64
Posts: 960

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

Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
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, 01:16 PM   #4
Senior Member
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
Look at

Especially the section on dlopen and dlclose
Old 05-01-2007, 01:41 PM   #5
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:
#gcc -c -fPIC mydev.c -o mydev.o
#gcc -shared mydev.o
Create executable file (linking with ddl)
#gcc mynewdev.c
Then when you take your program to run on other machines make sure you copy *.so file to /lib/ or /usr/lib too.

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:
#gcc -c mydev.c -o mydev.o
#ar rcs libmydev.a mydev.o
Create executable file (linking with static):
#gcc -static mynewdev.c -lmydev


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 01:35 AM
Dynamically sized objects in shared memory jtshaw Programming 2 03-16-2005 10:12 AM
any links on linking, loading shared libraries, shared objects. etc? ananthbv Programming 0 02-03-2005 07:47 AM
Creating Shared objects Anup Kumar Programming 1 09-11-2004 11:45 PM
g++ missing shared objects pinguwin Linux - Software 0 05-27-2004 08:38 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:10 PM.

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