[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #BGM-104794]: building statically linked netCDF exes



> To Unidata support,
>
> This is quite possibly a bug report, although it is also well possible that
> I am just doing something wrong.
>
> I am trying to build netCDF 3.6.2 including fully statically linked
> versions of the ncdump and ncgen executables (platform: SuSE 10.0, 32-bit).
>
> If I try:
>
> export LDFLAGS="-static"
> ./configure --prefix=/some/path --disable-f77 --disable-f90
> make
> make install
>
> then it passes "-static" to the libtool script which is created, but this
> is not sufficient to invoke gcc with the "-static" flag:
>
> /bin/sh ../libtool --tag=CC --mode=link cc  -g -O2  -static \
> -o ncdump ncdump.o vardata.o dumplib.o -lm  ../libsrc/libnetcdf.la
> libtool: link: cc -g -O2 -o ncdump ncdump.o vardata.o dumplib.o \
> -lm ../libsrc/.libs/libnetcdf.a
>
> (long lines split by me here just for sake of email readability)
>
> To get "-static" passed to gcc, you need to pass "-all-static" to libtool:
>
> /bin/sh ../libtool --tag=CC --mode=link cc  -g -O2  -all-static \
> -o ncdump  ncdump.o vardata.o dumplib.o -lm  ../libsrc/libnetcdf.la
> libtool: link: cc -static -g -O2 -o ncdump ncdump.o vardata.o \
> dumplib.o -lm ../libsrc/.libs/libnetcdf.a
>
> But if I try "export LDFLAGS=-all-static", then this will fail at the
> configure stage, because it tries to pass it to gcc directly:
>
> configure: error: C compiler cannot create executables
> See `config.log' for more details.
>
> --- from config.log ---
> configure:3359: cc   -all-static conftest.c  >&5
> cc1: error: unrecognized command line option "-all-static"
> -----------------------
>
> It is possible to work around it by doing (still in bash syntax):
>
> LDFLAGS="-static" \
> ./configure --prefix=/some/path --disable-f77 --disable-f90
> make LDFLAGS=-all-static
> make install
>
> But it seems a bit of a kludge.  I couldn't see a clean way to do what I
> was trying.  It doesn't quite seem right that the flags specified in
> LDFLAGS should be passed to two different programs -- to the linker command
> (in fact cc) during configure, and to libtool during make -- though maybe
> it's just "-static" that causes a problem because libtool will pass most
> other flags straight through to the link command.
>
> I just thought I'd raise this with you, and I'd be interested in what you
> have to say.
>
> Many thanks,
> Alan
>
>

Howdy Alan!

I think if you set CFLAGS to -static it will pass it to the compiler.

Also, the build does shared libraries only with the --enable-shared flag. So I
think a default build will give you statically linked utilities. Please tell me
if that is not the case for you. Shared libraries are a new feature for us and
so we have a lot to learn in this area.

If I may ask, why do you want statically linked utilities? What is it about
your situation that makes you not want to use shared libraries?

Thanks!

Ed

Ticket Details
===================
Ticket ID: BGM-104794
Department: Support netCDF
Priority: Normal
Status: Closed