问题
I am trying to wrap some Fortran using f90wrap, which is built on f2py. (I can use f2py, but I want to extend some code to use derived types).
Here is a simple .f90
test code that I have tried to wrap:
module test_mod
integer::p
end module
I have compiled and wrapped with the following commands:
gfortran -fPIC -c test.f90
f90wrap -m test test.f90
f2py-f90wrap -c -m _test f90wrap_*.f90
When I run:
python test.py
on this test.py
file which is produced:
import _test
import f90wrap.runtime
import logging
class Test_Mod(f90wrap.runtime.FortranModule):
"""
Module test_mod
Defined at test.f90 lines 1-3
"""
@property
def p(self):
"""
Element p ftype=integer pytype=int
Defined at test.f90 line 3
"""
return _test.f90wrap_test_mod__get__p()
@p.setter
def p(self, p):
_test.f90wrap_test_mod__set__p(p)
def __str__(self):
ret = ['<test_mod>{\n']
ret.append(' p : ')
ret.append(repr(self.p))
ret.append('}')
return ''.join(ret)
_dt_array_initialisers = []
test_mod = Test_Mod()
I get the following error:
File "test.py", line 1, in <module>
import _test
ImportError: _test.cpython-35m-x86_64-linux-gnu.so: undefined symbol: __test_mod_MOD_p
Having dug through the f90-wrap repo and looked at the makefile for some of the tests in there I see the same process on the following .f90 file doesn't produce the same issue:
module testextends_mod
PUBLIC
! -----------------------------------------------
type Superclass
! IN: Ask subroutine to stop in the middle.
integer :: stop_at = -1 ! -1 --> don't stop
end type Superclass
type, extends(Superclass) :: Subclass1
integer :: nl
end type
type, extends(Superclass) :: Subclass2
integer :: nl
end type
end module
Can anyone see what exactly I am doing wrong here?
回答1:
The following works:
gfortran -c -O3 -fPIC test.f90
f90wrap -v -m test test.f90
f2py-f90wrap -c -m _test f90wrap_test.f90 test.o
来源:https://stackoverflow.com/questions/48460221/f2py-f90wrap-error-undefined-symbol-test-mod-mod-p