[Top][All Lists]

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

using the static library after building the shared library...

From: Ed Hartnett
Subject: using the static library after building the shared library...
Date: Sat, 29 Jul 2006 05:33:34 -0600
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Howdy all!

I have some questions about how to use a static library after building
and installing both shared and static, when the library is built with

I am maintaining a popular earth science data library, which, until
now, has always been built as a static library. But I have recently
converted it to libtool.

For example, I built my library and install it with prefix
/home/ed/n3_install. Now I have a /home/ed/n3_install/lib directory,
with both static and shared versions of the library.


  -rw-r--r--  1 ed ustaff  795368 Jul 29 05:01 libnetcdf.a
  -rwxr-xr-x  1 ed ustaff     968 Jul 29 05:00
  lrwxrwxrwx  1 ed ustaff      18 Jul 29 05:00 ->
  lrwxrwxrwx  1 ed ustaff      18 Jul 29 05:00 ->
  -rwxr-xr-x  1 ed ustaff  538366 Jul 29 05:00

Now I write a little test program, test.c, which calls one of the
library functions, and build it like this:

gcc test.c -I/home/ed/n3_install/include -L/home/ed/n3_install/lib -lnetcdf

But when I run this, it tells me that it can't find the shared library...

bash-3.00$ ./a.out 
./a.out: error while loading shared libraries: cannot
open shared object file: No such file or directory

However, if I use the -static flag, it works as I expect:

gcc -static test.c -I/home/ed/n3_install/include -L/home/ed/n3_install/lib 
bash-3.00$ ./a.out
library version: "3.6.2-beta4" of Jul 29 2006 05:00:56 $

So apparently if there is a shared library gcc will use it by
default. And to use the static one, you have to add the -static flag
to gcc. Is this correct?

Are other compilers the same in these respects? Do they generally use
the shared library by default, and require some flags to use the
static one?

The immediate result is that if I have the build and install shared
libraries, I am going to break everyone's makefiles on that
machine. :-(

It's a shame that gcc didn't take the other approach, of using static
libraries unless told to use the shared ones. That way, users could
install the shared libraries on their machine and start to use them,
without breaking all existing builds on that machine.

As it is, I think most of my users will not want shared libraries at
all, if it means that all their Makefiles break and have to be
changed. And, even worse, they have to be changed in a
compiler-dependent way! (Which means each and every user would email
me and ask me how to do it for their compiler!)

Hopefully I am missing something here?



Ed Hartnett  -- address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]