LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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-08-2013, 01:45 PM   #1
brownwrap
Member
 
Registered: Jan 2010
Posts: 121

Rep: Reputation: 16
gfrtran capable of static and dynamic linking


OK, let me start of by saying I am not a programmer. I am a system administrator that has been asked to install software. I have been asked to install a version of gfortran that can be used to link using both static or dynamic methods. My question is why wouldn't gfortran be able to do this out of the box? Aparently the gfortran that is currently installed can't, thus the reason my user is requesting a reinstallation. Here is the output of gfortran -v

Code:
[ramos@kahuna ~]$ gfortran -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) 
[ramos@kahuna ~]$
 
Old 10-08-2013, 02:04 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,871
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
> Aparently the gfortran that is currently installed can't

What tests proved this statement?

PS: by 'dynamic method' you mean 'using/creating shared libs'?
 
Old 10-08-2013, 04:56 PM   #3
turtleli
Member
 
Registered: Aug 2012
Location: UK
Posts: 206

Rep: Reputation: Disabled
Have you checked whether static glibc libraries are installed? I believe Red Hat based distros do not install them by default (I could be wrong here).

On a HPC (Scientific Linux) I have access to I cannot compile static fortran programs because it's missing some static libraries (specifically libm.a). On my Slackware desktop the relevant static libraries are present and I can build static programs with that. I do not think it is related to the compiler.
 
Old 10-08-2013, 05:12 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Probably just missing the static libs. As turtleli said, they're separate from the dynamic libs and often aren't installed by default. On RHEL/CentOS, the dynamic libs are part of the package "glibc", while the static libs are in "glibc-static". Remember that there are 32-bit and 64-bit versions of each:

glibc.x86_64
glibc.i686
glibc-static.x86_64
glibc-static.i686

RPM-based distros are a champ with multilib setups, so feel free to install all four if you want.

Last edited by suicidaleggroll; 10-08-2013 at 05:13 PM.
 
Old 10-09-2013, 01:01 PM   #5
brownwrap
Member
 
Registered: Jan 2010
Posts: 121

Original Poster
Rep: Reputation: 16
Thank you all for the insightful information. I am not quite there yet though. What is really curious is, the user who requested the new compiler gave me a test program. On the SAME machine, it runs for me, but not for him. We are in fact using Red Hat, and all of our machine use RH Satelite to configure machines, though this one may be slightly different. I followed the suggestions and installed glibc.static, still get the same result on a test box I have set up.

Code:
compile options: '-I/tmp/tmphWYLPN/src.linux-x86_64-2.7 -I/opt/ActivePython-2.7/lib/python2.7/site-packages/numpy/core/include -I/opt/ActivePython-2.7/include/python2.7 -c'
gfortran:f90: test_f2py.f90
/usr/bin/gfortran -Wall -Wall -shared -static-libgfortran /tmp/tmphWYLPN/tmp/tmphWYLPN/src.linux-x86_64-2.7/test_f2pymodule.o /tmp/tmphWYLPN/tmp/tmphWYLPN/src.linux-x86_64-2.7/fortranobject.o /tmp/tmphWYLPN/test_f2py.o -lgfortran -o ./test_f2py.so
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgfortran.a(transfer.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgfortran.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgfortran.a(transfer.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgfortran.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
error: Command "/usr/bin/gfortran -Wall -Wall -shared -static-libgfortran /tmp/tmphWYLPN/tmp/tmphWYLPN/src.linux-x86_64-2.7/test_f2pymodule.o /tmp/tmphWYLPN/tmp/tmphWYLPN/src.linux-x86_64-2.7/fortranobject.o /tmp/tmphWYLPN/test_f2py.o -lgfortran -o ./test_f2py.so" failed with exit status 1
make: *** [test_f2py.so] Error 1
 
Old 10-09-2013, 03:36 PM   #6
turtleli
Member
 
Registered: Aug 2012
Location: UK
Posts: 206

Rep: Reputation: Disabled
Ok. From your latest information I don't think it has anything to do with static glibc. I thought your user was creating static programs (and using the -static option) but it seems your user is trying to make static and dynamic libraries instead.

If this is indeed the case then your user might be building the libraries wrong. The compile options strike me as peculiar since "-shared" and "-static-libgfortran" aren't normally used together. The options also do not work together when attempting to build a shared library in Scientific Linux, which will apply to Red Hat as well.

Perhaps you should direct your user to this fortranwiki faq, which shows the correct way to create shared and static libraries.
 
Old 10-09-2013, 06:42 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,673
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
I cannot speak directly to the case of "the GNU Fortran compiler," but I think that I can say that the decision of "static vs. dynamic linking" is going to be "a compiler option."

When your program's source-code has been successfully processed, the compiler now has a choice: should it resolve all of the external-library dependencies now ("early binding"), or should it instead generate a program that will attempt to resolve those dependencies at runtime ("late binding")? The choice is yours. (And the real answer ... see below ... is "both.")

In the case of early binding, the requisite libraries will need to be available to the linker (as *.o files immediately. The necessary subroutines (object code ...) will be retrieved from the libraries and bound into the executable program. If they are not available right now, the step will not succeed.

In the case of late binding, the program will be built in such a way that it will only successfully execute if the necessary libraries *.so can be located (by the so-called "dynaloader").

Obviously, all programs employ more-or-less of a mixture of these two techniques. Even an early-bound program will still be generated with numerous late-binding dependencies on (at least ...) glibc.
 
Old 10-09-2013, 11:45 PM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,871
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
What do you really want? (Or what does your user really want?) Is this a random play with linker-options (-shared, -static-libgfortran, -lgfortran), or does he actually want to get something? A shared object that integrates libgfortran.a? That is not possible, because objects in libgfortran.a aren't usable that way (cf -fPIC compiler-option).
 
  


Reply



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
Static and dynamic linking qwerty4061 Linux - Newbie 2 12-27-2011 11:29 AM
Static linking vs. dynamic linking? posix_memalign Programming 13 04-18-2010 02:27 PM
static and dynamic linking zb10948 Programming 1 04-27-2009 03:48 AM
Linking a static library to a dynamic one delta4s Programming 2 09-28-2006 01:24 AM
Static/dynamic linking ugenn Linux - Software 0 12-15-2002 11:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:02 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration