LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   gcc errors on static, but NOT dynamic, linking (https://www.linuxquestions.org/questions/programming-9/gcc-errors-on-static-but-not-dynamic-linking-673829/)

MALDATA 10-02-2008 05:00 PM

gcc errors on static, but NOT dynamic, linking
 
I'm just writing some little example programs to teach myself some C. I wrote one which uses the lapack library... specifically it uses the DGESV function. To compile it, I issue the following command:

gcc lsq.c -o lsq.x -g -O0 -lm -llapack -lblas

And that works just fine. One thing I wanted to try also was to link the libraries statically. In general I've heard this is bad practice and should only be used in special cases, but again, this is supposed to be a learning experience. Anyway, as far as I can tell, all I need to do is add the -static flag before the libraries, but if I do

gcc lsq.c -o lsq.x -g -O0 -static -lm -llapack -lblas

I get a whole list of errors like this:

/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../liblapack.a(dlamch.o): In function `dlamch_':
(.text+0xc35): undefined reference to `_gfortran_pow_r8_i4'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../liblapack.a(dlamch.o): In function `dlamch_':
(.text+0xc67): undefined reference to `_gfortran_pow_r8_i4'

There are a lot of them, all undefined references to lapack functions.

I have the devel packages installed for lapack and blas, so the static libraries are in the path. What other differences are there between static and shared libraries that I would get these errors? I'm obviously missing something, I just don't know what.

Thanks!

raconteur 10-02-2008 05:50 PM

At the risk of asking the obvious... could you possibly have multiple copies of the libraries installed?

MALDATA 10-02-2008 07:52 PM

Nope, just the static and shared libraries. No other versions or scattered copies. There's another one ending in _pic, but I don't know what it is. Here's the output of ll /usr/lib/liblapack*:

/usr/lib/liblapack.a
/usr/lib/liblapack_pic.a
/usr/lib/liblapack.so -> liblapack.so.3.1.1
/usr/lib/liblapack.so.3 -> liblapack.so.3.1.1
/usr/lib/liblapack.so.3.1 -> liblapack.so.3.1.1
/usr/lib/liblapack.so.3.1.1

Anything else we might be missing?

Thanks!

paulsm4 10-02-2008 09:43 PM

Clearly "apack" needs the FORTRAN runtime library, too.

SUGGESTION:
Try linking your program with Gnu Fortran (e.g. "g77") instead of Gnu C and see what happens...

MALDATA 10-02-2008 09:52 PM

Linking with g77 didn't change anything (it worked without the -static flag, but I got the same errors when I added it).

I've got the gfortran runtime package installed. Shouldn't that only required for dynamically linked programs? I'm not sure why that would make a difference here.

Thanks for the suggestions. Any other ideas?

paulsm4 10-02-2008 11:20 PM

Quote:

I've got the gfortran runtime package installed. Shouldn't that only required for dynamically linked programs? I'm not sure why that would make a difference here.
Maybe because "apack" depends on a GFortran library...
... and "-static" specifies that libapack.xx (and everything afterwards) *must* be static...
... but your GFortran package doesn't happen to *have* a static library (only .so)?


All times are GMT -5. The time now is 07:52 PM.