Novak Elliott wrote:
> > Dynamic libraries are a bit more involved.
> >
> > First, all source files need to be compiled with the -fPIC switch to
> > create position-independant (relocatable) code.
> >
> > Then, to create the shared library itself, use e.g.
> >
> > gcc -shared -o libfoo.so.1.2 -Wl,-soname,libfoo.so.1 file1.o file2.o ...
> >
> > The `-Wl,-soname,libfoo.so.1' sets the library's `soname' to
> > libfoo.so.1.
>
> Apologies, i am using latest solaris (sunos 5.6) and gcc 2.7 but i thought
> i'd try this list since its usually so helpful (no solaris equivalent).
>
> from the man page there is no -soname option.
>From which manpage?
Without -c, gcc invokes the linker. The -Wl switch passes arguments to
the linker. Its argument is split according to the commas, and the
resulting arguments are passed verbatim to the linker. So the command:
gcc -shared -o libfoo.so.1.2 -Wl,-soname,libfoo.so.1 file1.o file2.o
would (on my system) invoke the linker using:
ld -m elf_i386 -shared -o libfoo.so.1.2 \
/usr/lib/crti.o /usr/lib/gcc-lib/i586-pc-linux-gnu/2.8.1/crtbeginS.o \
-L/usr/lib/gcc-lib/i586-pc-linux-gnu/2.8.1
-L/usr/i586-pc-linux-gnu/lib \
-soname libfoo.so.1 file1.o file2.o -lgcc -lc -lgcc \
/usr/lib/gcc-lib/i586-pc-linux-gnu/2.8.1/crtendS.o /usr/lib/crtn.o
Any -Wl argument needs to be compatible with the linker that gcc uses
on your system (presumably the Solaris linker).
> I have a library consisting of a single header file and a corresponding
> source file: libcvg.h, libcvg.c
>
> i build the library as follows:
>
> gcc -Wall -ansi -pedantic -g -fPIC -O3 -c libcvg.c
> gcc -shared -o libcvg.so.1.0 -Wl,-soname,libcvg.so.1 libcvg.o
>
> with the following errors:
>
> ld: warning: option -o appears more than once, first setting taken
> ld: fatal: file libcvg.so.1: open failed: No such file or directory
> ld: fatal: File processing errors. No output written to libcvg.so.1.0
>
> the first warning appears to come from having -shared and -o
> => if i remove -o, the first warning goes away
>
> i've tried many different arrangements of the above compiles, to no avail.
The error:
> ld: fatal: file libcvg.so.1: open failed: No such file or directory
comes from your linker not understanding -soname, so it thinks that
libcvg.so.1 is an input file, rather than the argument to the -soname
switch.
> It didn't work under linux either (RH5.0, some updated RPMs) same errors
> but it didn't complain about the -o option.
I have no idea why it wouldn't work on Linux/ELF. Have you replaced
GNU ld with some other ld?
--
Glynn Clements <[EMAIL PROTECTED]>