作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
使用 F2PY 作为包装器,是否可以使用带有子程序调用的子程序?如果是这样,怎么做到的?
如果我不清楚,我的意思是这样的:
SUBROUTINE average(a, b, out)
real a, b, out
cf2py intent(in) a, b
cf2py intent(out) out
call add(a, b, out)
out=out/2
END
添加子程序如下:
subroutine add(a, b, out)
real a, b, out
out = a + b
return
end
尝试 f2py -c -m average average.f 并导入 python 我得到:
ImportError: ./average.so: undefined symbol: add_
此外,向第二个子例程添加意图并不能解决问题。
最佳答案
您需要在编译命令中包含包含add
的文件,例如
f2py -c -m average average.f add.f
您导入的共享库需要在导入时解析其引用,这意味着它们需要包含在库中或链接到库。您可以像这样将函数保存在单独的库中:
gfortran -shared -fPIC -o add.so add.f
f2py -c -m average average.f add.so
这将生成一个 python 模块,该模块本身不包含 add
,但该函数将具有对 add.so
的运行时链接依赖性。
关于python - 我可以在带有子例程调用的子例程上使用 F2PY 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31949748/
我是一名优秀的程序员,十分优秀!