在我的.h文件中,我有以下内容:
#include <iostream>
class Foo {
public:
void bar() {
std::cout << "Hello world";
}
};
在Python文件中,我使用以下命令调用:
^{pr2}$我创建了一个.dylib,因为我不相信在mac上用GCC创建共享库是可能的,但是,我可能错了。我得到以下错误:
Traceback (most recent call last):
File "main.py", line 3, in <module>
lib = cdll.LoadLibary('./libfoo.1.dylib')
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py",
line 423, in __getattr__
dll = self._dlltype(name)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py",
line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(LoadLibary, 6): image not found
但是它被找到了,库(.dylib)就在同一个目录中。。我哪里出错了?在
ctypes
库不了解c++,如果要使用ctypes
,则需要用c编写共享库。在您可以看看类似于http://www.swig.org的东西,它可以钩住用c++编写的共享库。在
相关问题 更多 >
编程相关推荐