파이썬에서 사용하려면 파일을 만들고 싶습니다. fortran 소스에서 공유 라이브러리를 만들려면 어떻게해야합니까?gfortran을 사용하여 공유 라이브러리를 만들 수 있습니까?
다음 코드와 같이 테스트했습니다.
gfortran -c mod.f90
#gfortran -c sub1.f90
gfortran -c func.f90
gfortran -shared -fPIC -o func.so func.f90 mod.o
하지만 파이썬으로 가져올 수 없습니다. Fortran 소스 코드에서 모듈 파일을 사용했습니다. 파이썬에서 fortran 소스 코드를 가져 왔습니다. 나는 옳은지 잘 모르겠습니다.
[===>14:47:59]f1:python
Python 2.7.2+ (default, Oct 4 2011, 20:03:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import func
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initfunc)
func.f90
-----------------------------------------
program func
use mod_test
switch1 = .true.
switch2 = .false.
x = 1.2
!call test(x, z)
print *, b, str, z, switch1, switch2
!print *, 'hello'
end program func
-----------------------------------------
mod.f90
-----------------------------------------
module mod_test
!implicit none
integer a
real x, y, z
real*8 :: b = 3.4
logical*2 switch1, switch2
character*5, parameter :: str = 'good'
end module mod_test
-----------------------------------------
sub1.f90
-----------------------------------------
subroutine test(input, output)
real, intent(in) :: input
real, intent(out) :: output
output = (input + input)
end subroutine
-----------------------------------------
또한 테스트했습니다 : fwrapc func.f90 --build --name = func --fcompiler = gnu95 --f90exec =/usr/bin/gfortran-4.6 -L/usr/lib/gcc/i686-linux-gnu /4.6 -lgfortran하지만 모듈을 찾을 수 없습니다. – wonjun