This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Creating static libraries using gcc


Hi guys,

> By the way, I dont know how to create shared library in Linux. this is
> what i've heard about it, but i don't know if it works.
> 
> g++ -fPIC -c file1.cpp
> g++ -fPIC -c file2.cpp
> 
> g++ -shared -o libshared.so file1.o
> how can I put file2.o in libshared.so?
> 
 Right, this is pretty much the standard way to build shared libraries
on linux and other unix flavors. The choice of compiler and options
needed does vary a bit. To build a shared library with more than 1
.o file, you simply list more than 1, it is that simple.

g++ -shared -o libshared.so *.o

> When I have a new file, is that right if I do
> 
> g++ newfile.cpp libshared.so?
> 

Maybe, i think, you can link with a shared library like that. I prefer
putting the libraries in a lib directory somewhere,so they don't clutter
my working directory, and use

g++ -o main -L/somepath/lib -lshared main.cpp

Yours sincerely,

Bjorn


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]