inv*_*rse 5 python ctypes ipython jupyter-notebook
我试图在 IPython 中执行 C 代码(使用 ctypes),但每次调用 C 函数时 IPython 都会崩溃。
文件test.c:
int func(){
return 10;
}
Run Code Online (Sandbox Code Playgroud)
在命令行中编译:
gcc -shared -o test.dll -fPIC test.c
Run Code Online (Sandbox Code Playgroud)
在同一目录中启动 IPython,然后运行:
In [1]: import ctypes
...: lib = ctypes.CDLL("test.dll")
...: lib.func()
Out[1]: 10
Run Code Online (Sandbox Code Playgroud)
输出Out[1]是正确的,但 IPython 在Out[1]: 10打印后立即崩溃。(有时它会在Out[1]: 10打印之前崩溃)
IPython 支持 ctypes 吗?
如果是,为什么会出现上述问题?
如果不是这样,是否有在 IPython/Jupyter Notebook 中使用 ctypes 的解决方法?
CDLL为WinDLL;见评论);不工作。从 TDM-GCC 切换到 Mingw-w64,这以某种方式解决了问题。
| 归档时间: |
|
| 查看次数: |
71 次 |
| 最近记录: |