This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Creating static libraries using gcc
- From: bjorn rohde jensen <shamus at tdcadsl dot dk>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 19 Mar 2002 11:42:24 +0100
- Subject: Re: Creating static libraries using gcc
- References: <B947031D966C464A9A4E6F567C73BA4D17963E@hue.cybersoft.vn>
- Reply-to: shamus at tdcadsl dot dk
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