LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to create shared objects and how are they useful (https://www.linuxquestions.org/questions/programming-9/how-to-create-shared-objects-and-how-are-they-useful-550363/)

jeevanladhe 05-01-2007 08:01 AM

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.

dasy2k1 05-01-2007 11:59 AM

this forum is primarrly for saying hi,
thsi woudl be better suited in the programming forum

XavierP 05-01-2007 01:09 PM

Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

tuxdev 05-01-2007 01:16 PM

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

Especially the section on dlopen and dlclose

haxpor 05-01-2007 01:41 PM

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


All times are GMT -5. The time now is 02:54 AM.