LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-02-2008, 05:00 PM   #1
MALDATA
Member
 
Registered: Mar 2005
Posts: 103

Rep: Reputation: 17
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!
 
Old 10-02-2008, 05:50 PM   #2
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 44
At the risk of asking the obvious... could you possibly have multiple copies of the libraries installed?
 
Old 10-02-2008, 07:52 PM   #3
MALDATA
Member
 
Registered: Mar 2005
Posts: 103

Original Poster
Rep: Reputation: 17
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!
 
Old 10-02-2008, 09:43 PM   #4
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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...
 
Old 10-02-2008, 09:52 PM   #5
MALDATA
Member
 
Registered: Mar 2005
Posts: 103

Original Poster
Rep: Reputation: 17
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?
 
Old 10-02-2008, 11:20 PM   #6
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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)?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LINUX - linking archive (static library) with shared (dynamic) library gurkama Programming 5 03-04-2007 11:11 PM
Linking a static library to a dynamic one delta4s Programming 2 09-28-2006 01:24 AM
dynamic linking joshknape Linux - Software 1 09-19-2005 09:43 PM
Finding and Linking Static Libraries with gcc neorich Programming 15 08-10-2003 04:03 PM
Static/dynamic linking ugenn Linux - Software 0 12-15-2002 11:01 PM


All times are GMT -5. The time now is 03:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration