Creating static libraries using gcc
bjorn rohde jensen
shamus@tdcadsl.dk
Tue Mar 19 02:50:00 GMT 2002
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
More information about the Gcc-help
mailing list