0

I have a Fortran shared library specified by:

C FILE: OTHER.F
      SUBROUTINE OTHER(FUN)
      EXTERNAL FUN 
      INTEGER I
      DO I=0,5
         PRINT *, FUN(I)
      ENDDO

      END SUBROUTINE
C END OF FILE OTHER.F

Which I compiled as follows: gfortran -shared -O2 other.f -o libother.so -fPIC

I have now another module:

C FILE: CALLBACK.F
      SUBROUTINE FOO(FUN,R)
      EXTERNAL FUN
      INTEGER I
      REAL*8 R
      R = 0D0 
      DO I=-5,5
         PRINT *, FUN(I)
         R = R + FUN(I)
      ENDDO

      CALL OTHER(FUN)
      END SUBROUTINE
C END OF FILE CALLBACK.F

And I wish to compile this module as a python module, using f2py. To achieve this, I have entered:

f2py -m callback -h callback.pyf callback.f

followed by:

f2py -c callback.pyf callback.f -L. -lother

I then use the Python interpreter to run:

import callback
callback.foo(lambda x: 1)

The expected behaviour is:

  1. print "1" eleven times (b/c of foo)
  2. print "1" six times (b/c of the call to other inside foo)
  3. return "11"

The observed behaviour is instead:

ImportError: libother.so: cannot open shared object file: No such file or directory

If I do nm callfun.so, I can see that other is undefined

astabada
  • 1,029
  • 4
  • 13
  • 26
  • Try to set `LD_LIBRARY_PATH=$PWD;$LD_LIBRARY_PATH` where $PWD is a directory with your `libother.so` – Laser Jun 30 '16 at 05:58
  • @Arseniy thanks but did not work. Even `f2py -c callback.pyf callback.f libother.so` compiles but results in the same `ImportError` – astabada Jul 01 '16 at 00:02
  • I'm trying to do this exact same thing with a different fortran source file. I think it has some issues with f2py though... it'll compile with gfortran fine, but once I try to compile with f2py (in any way... I've tried like 10) I get "unresolved external symbol" errors - three of them. Is there a way to do this without invoking f2py? – Yoshi Nov 07 '17 at 01:33

0 Answers0