This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Dynamic Linking Library Problem Using GCC
- From: "Martin York" <martin dot york at veritas dot com>
- To: "Olivier Rochecouste" <olivier dot rochecouste at irisa dot fr>,<gcc-help at gcc dot gnu dot org>
- Date: Mon, 13 Dec 2004 10:32:22 -0600
- Subject: RE: Dynamic Linking Library Problem Using GCC
Hi Cheok,
By specifying the argument:
-Wl,-soname,libmean.so.1
The executable will search for 'libmean.so.1' file at runtime to load.
But this does not exist. So you would also need to create a link from
your actual library to this name.
So in addition to the suggestion by 'Oliver' you will need to add
"ln -s libmean.so.1.0.1 libmean.so.1"
I am not sure why you are setting the 'soname' to a different name to
the resulting library, this seems dangerous to me (unless you can always
guarantee binary compatibility between all versions of libmean.so.1.X).
The general rule for building shared libs I use is:
g++ -shared -Wl,-soname,lib<LIBNAME>.so.<MAJ_VER>.<MIN_VER> -o
lib<LIBNAME>.so.<MAJ_VER>.<MIN_VER> <FILES>
ln -s lib<LIBNAME>.so.<MAJ_VER>.<MIN_VER> lib<LIBNAME>.so.<MAJ_VER>
ln -s lib<LIBNAME>.so.<MAJ_VER> lib<LIBNAME>.so
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Olivier Rochecouste
Sent: 13 December 2004 10:30
To: gcc-help@gcc.gnu.org
Subject: Re: Dynamic Linking Library Problem Using GCC
Hi Cheok,
I'm not an expert but I think you should make a symlink to your shared
library:
"ln -s libmean.so.1.0.1 libmean.so"
ld should be able to find the .so now
--
Olivier
> Hi,
>
> I read through the tutorial
> http://www.adp-gmbh.ch/cpp/gcc/create_lib.html in buidling dynamic
> library using gcc. It is interesting.
> However, after following the steps inside the tutorial, it doesn't
> work in my system.
>
> Here is the sequence of steps which I had performed:
>
> [yccheok@localhost project]$ ls -al
> total 28
> drwxrwxr-x 2 yccheok yccheok 4096 Dec 13 01:16 .
> drwx------ 65 yccheok yccheok 12288 Dec 13 00:58 ..
> -rw-rw-r-- 1 yccheok yccheok 56 Dec 13 00:48
> calc_mean.c
> -rw-rw-r-- 1 yccheok yccheok 29 Dec 13 00:48
> calc_mean.h
> -rw-rw-r-- 1 yccheok yccheok 224 Dec 13 00:49
> main.c
> [yccheok@localhost project]$ gcc -c -fPIC calc_mean.c -o calc_mean.o
> [yccheok@localhost project]$ gcc -shared
> -Wl,-soname,libmean.so.1 -o
> libmean.so.1.0.1 calc_mean.o
> [yccheok@localhost project]$ gcc main.c -o dynamically_linked -L.
> -lmean
> /usr/bin/ld: cannot find -lmean
> collect2: ld returned 1 exit status
> [yccheok@localhost project]$ ls -al
> total 40
> drwxrwxr-x 2 yccheok yccheok 4096 Dec 13 01:17 .
> drwx------ 65 yccheok yccheok 12288 Dec 13 00:58 ..
> -rw-rw-r-- 1 yccheok yccheok 56 Dec 13 00:48
> calc_mean.c
> -rw-rw-r-- 1 yccheok yccheok 29 Dec 13 00:48
> calc_mean.h
> -rw-rw-r-- 1 yccheok yccheok 908 Dec 13 01:16
> calc_mean.o
> -rwxrwxr-x 1 yccheok yccheok 4349 Dec 13 01:16
> libmean.so.1.0.1
> -rw-rw-r-- 1 yccheok yccheok 224 Dec 13 00:49
> main.c
> [yccheok@localhost project]$
>
> Can you please advice on why the ld cannot find the mean library. Do I
> need to prior perform anything with ldconfig before i dynamic linked
> my main application with the mean library?
>
> Thank you!
>
> -cheok
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>