ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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:
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
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.
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.
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.