[f2py] ifort works, gfortran doesn't

KASSBOHM <[email protected]> Wed, 22 Aug 2012 19:07:53 +0200 (CEST)
Newsgroups gmane.comp.python.f2py.user
Message-ID <alpine.DEB.2.02.1208221905470.29273@thnkpd>
Sorry if you read this mail twice...

I have a function in tools.f, which I would like to use from within Python.

I use static libs from some application. For ifort, the static lib to be linked 
is called "ifort.a". For gfortran, the static libs are called "gnu4_1.a" and 
"gnu4_2.a". These are third party libs, which I cannot modify.

1) I can use the function in tools.f from within Fortran compiling with 
"gfortran" like this:

  gfortran -o a.run main.f .../tools.a .../gnu4_1.a .../gnu4_2.a

With this, I use a main program main.f calling my tools-function.

2) I can also use it with Python compiling with f2py and "intel-ifort" doing:

  f2py -c .../tools.f -m tools -L.../ -lifort

I get a tools.so ready to be used with Python.

3) But I cannot (but would like to) use it with Python compiling with f2py and 
"gfortran" doing:

  f2py --fcompiler=gfortran -c .../tools.f -m tools -L.../ -lgnu4_1 -lgnu4_2

But this doesn't work.

Error message is:

/usr/bin/gfortran -Wall -Wall -shared 
/tmp/.../src.linux-x86_64-2.7/toolsmodule.o 
/tmp/.../src.linux-x86_64-2.7/fortranobject.o /tmp/tools.o -L/.../ -lgnu4_1 
-lgnu4_2 -lgfortran -o ./tools.so

/usr/bin/ld: .../gnu4_2.a(stop.o): relocation R_X86_64_32 against 
`.rodata.str1.1' can not be used when making a shared object; recompile with 
-fPIC

But I cannot compile the application libs...

Any help or ideas what I could try?
Sven