This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc static library issue -- libdl
- To: Bin Zhou <binzhou at pop-star dot net dot cn>
- Subject: Re: gcc static library issue -- libdl
- From: Kevin Sindhu <kevin at tgivan dot com>
- Date: Wed, 31 Oct 2001 09:05:46 -0800
- Cc: gcc-help at gcc dot gnu dot org, gcc at gcc dot gnu dot org, crossgcc at sourceware dot cygnus dot com, crossgcc at sources dot redhat dot com, binzhou at tgivan dot com, Rod Thomson <rod at tgivan dot com>, Stephen Rasku <stephen at tgivan dot com>
- References: <016101c16285$44e81f40$50c80ac0@acer>
Hello,
On Wed, Oct 31, 2001 at 07:28:26PM -0800, Bin Zhou so wrote:
> I am using gcc2.95.2 on Solaris2.8 on Intelx86.
> I use the option "-static" at the linkage phase, in order to link to
> gcc libraries staticly (get rid of dynamic libraries such as
> libstdc++.so at running time).
[...]
> Since my source code references to system functions such as
> "dlclose" and "dlsym" etc, so the "libdl" is required for static
> linkage. Therefore, I also added "-ldl" for linkage. The problem is
> that the linker reports an error saying that "can not find -ldl".
Sun does not ship with a statically linked libdl and does not usually
want people to ship statically linked programs. There are many
reasons to this and primarily they are be summed up here:
http://marc.theaimsgroup.com/?l=openssh-unix-dev&m=98563522332517&w=2
> I checked /usr/lib and /usr/local/lib, I can only see
> libdl.so/libdl.so.1, but could not find libdl.a
There is none.
> However, Redhat have both the libdl.a and libdl.so.
Of course.
> Where can I get the libdl.a for Solaris2.8 on Intelx86 or there is
> an altnative library I can link to.
You have two alternatives:
1) Get the Solaris 2.8 source code and compile it. However due to
strict licensing restrictions, this will not apply when we ship the
product.
2) ^BETTER^ alternative.
See attached dlstubs.c file (derived from /usr/include/dlfcn.h and
thanks to Hal <hal@deer-run.com>).
Compile the attached file with gcc such as:
gcc -c 02 -g dlstubs.o dlstubs.c
Then use this object file with your target and compile it with static
flag. For example,
gcc -static -o bar foo.o dlstubs.o -l{yourlibs}
> Thanks a lot for any comments,
Hope that helps.
Regards
--
Kevin Sindhu <kevin at tgivan dot com>
Systems Engineer
TGI Technologies Inc.
107 E 3rd Avenue Tel: (604) 872-6676 Ext 321
British Columbia V5T 1C7 Fax: (604) 872-6601
Canada.
#include <sys/types.h>
#include <dlfcn.h>
/* dl*() stub routines for static compilation. Prepared from
/usr/include/dlfcn.h by Hal Pomeranz <hal@deer-run.com> */
void *dlopen(const char *str, int x) {}
void *dlsym(void *ptr, const char *str) {}
int dlclose(void *ptr) {}
char *dlerror() {}
void *dlmopen(Lmid_t a, const char *str, int x) {}
int dladdr(void *ptr1, Dl_info *ptr2) {}
int dldump(const char *str1, const char *str2, int x) {}
int dlinfo(void *ptr1, int x, void *ptr2) {}
void *_dlopen(const char *str, int x) {}
void *_dlsym(void *ptr, const char *str) {}
int _dlclose(void *ptr) {}
char *_dlerror() {}
void *_dlmopen(Lmid_t a, const char *str, int x) {}
int _dladdr(void *ptr1, Dl_info *ptr2) {}
int _dldump(const char *str1, const char *str2, int x) {}
int _dlinfo(void *ptr1, int x, void *ptr2) {}