View Full Version: Shared Object file

C++ Learning Community > C++ for Linux > Shared Object file


Title: Shared Object file
Description: linking


as_felix - October 14, 2005 05:37 AM (GMT)
Hi All,

I created the Shared Object file using

g++ -shared -fPIC myprog.cpp -o myso.so

.so file is created.

But i don't know how to link this to my client program......

Pls explain this......


Thanks

C-Man - October 14, 2005 08:00 AM (GMT)
i'm a bit comfused here
.so is for linux and from this post http://invisionfree.com/forums/CPPlearning...wtopic=4814&hl=
it looks like your coding for windows O.o

Consumed - October 14, 2005 09:06 AM (GMT)
QUOTE
g++ -shared myprog.cpp -o myso.so -Wl,--out-implib,libmyso.a

QUOTE
g++ prog_that_uses_myso.cpp -o prog libmyso.a


-Consumed

myork - October 14, 2005 01:58 PM (GMT)

CODE
# Build object file
g++ -c sharedFile1.cpp

# Build shared library
g++ -shared -o libshared.so sharedFile1.o

# Link executable against shared library
g++ main.cpp -L./ -lshared

# Before you can run the executable you need to put the library where
# the dynamic loader can find it.
# options are /lib
# or set environement variable LD_LIBRARY_PATH

setenv LD_LIBRARY_PATH .
./a.out

Nintendofreak88 - October 14, 2005 09:09 PM (GMT)
Why does linux require libraries on run time? Is there a way to fix this so programs are easier to distribute?

ramirez - October 15, 2005 06:28 AM (GMT)
Umm, the point is that they are dynamic. :P
If you don't want that, then just use static libraries (which always isn't available though).

myork - October 15, 2005 12:49 PM (GMT)
QUOTE (Nintendofreak88 @ Oct 14 2005, 04:09 PM)
Why does linux require libraries on run time? Is there a way to fix this so programs are easier to distribute?


Yes.
Dont build shared libs.
CODE
g++ main.cpp sharedFILE1.cpp




Hosted for free by InvisionFree