🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #42918

Re: gcc -static under Solaris2.4

#42918
From: Casper H.S. Dik - Network Securi...
Date: Wed, 18 Oct 1995 00:00
73 lines
3371 bytes
Adam Cable <cable@hyperia.nmsu.edu> writes:

>  Im trying to compile something to be static wtih gcc 2.7.0 in
>a Solaris 2.4 enviroment.    What seems to be happening is that
>libc.a wants to access nss_deffinder.o.  When I compile dynamically,
>and check my program with ldd, it depends on libc.so and libdl.so.  So
>I figure that nss_deffinder is in libdl and of course their is no
>libdl.a.  So how do I compile something statically in gcc and
>still bring in libdl.so?

The solaris FAQ says:

6.21) I have problems linking my application statically.

    In Solaris 2.x static linking is not supported for any of the
    system libraries.  All the functions that use /etc/nsswitch.conf
    (getXXXbyYYY, getpwXXX, etc) require the dynamic linker to
    load the code to load these functions.  It is not possible
    to write configurable/extensible functions in such a way that
    dynamic linking is not required.  E.g., you can add your own
    nsswitch.conf backend which would not be known to programs
    statically linked to only the standard backend code.

    Programs that link statically against any of the OS libraries
    may not run in the next release and are not ABI compliant.

    If you don't care about ABI compliance, i.e., you won't
    ship you program as a product and don't care that you may
    need to recompile after an OS upgrade, here are some of your
    options:

    Link dynamically against all but libdl:

	cc -Bstatic ....  -Bdynamic -ldl -Bstatic

    Link against dl* stubs (gethostbyXXX, getpwXXX etc won't work any
    longer):

	char *dlopen() { return 0;}
	int dlclose() { return 0;}
	char *dlsym() { return 0;}
	char *dlerror() { return "dynamic linking not loaded";}

    If you don't want any dependencies on /usr, link against the dynamic
    libs in /etc/lib:

	cc -Bstatic ... -Bdynamic -R/etc/lib -Wl,-I/etc/lib/ld.so.1 -ldl
		-Bstatic ....

    If you still get undefined symbols, check with ldd for all your
    libraries if they have any dynamic dependencies.  E.g.,

	% ldd /usr/lib/libsocket.so.1
		libnsl.so.1 =>   /usr/lib/libnsl.so.1
		libdl.so.1 =>    /usr/lib/libdl.so.1
		libc.so.1 =>     /usr/lib/libc.so.1
		libintl.so.1 =>  /usr/lib/libintl.so.1
		libw.so.1 =>     /usr/lib/libw.so.1

    tells you that if you want to link libsocket statically,
    you need to link with -lnsl -ldl -lc -lintl and -lw as well.


    --- end of excerpt from the FAQ

Questions marked with a * or + have been changed or added since
the FAQ was last posted

The most recently posted version of the FAQ is available from
ftp.fwi.uva.nl in directory /pub/solaris
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Technical Details
Message-ID: <462esk$ad6@sungy.Germany.Sun.COM>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <461ddo$t2f@bubba.NMSU.Edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,fea7103174cfcdbd
X-Google-Attributes: gid11318c,public
X-Google-Thread: 11035d,fea7103174cfcdbd
X-Google-Attributes: gid11035d,public
From: Casper.Dik@Holland.Sun.COM (Casper H.S. Dik - Network Security Engineer)
Subject: Re: gcc -static under Solaris2.4
Date: 1995/10/18
Message-ID: <462esk$ad6@sungy.Germany.Sun.COM>
X-Deja-AN: 117732514
distribution: inet
references: <461ddo$t2f@bubba.NMSU.Edu>
organization: Sun Microsystems, Netherlands
newsgroups: gnu.gcc.help,comp.unix.solaris