gcc static library issue -- libdl

Kevin Sindhu kevin@tgivan.com
Wed Oct 31 09:07:00 GMT 2001


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:


> 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

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.


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 

More information about the crossgcc mailing list