使用DyLIB在Python中创建C++包装器

2024-04-25 07:03:25 发布

您现在位置:Python中文网/ 问答频道 /正文

基本上我试图在Python中开发一个包装器,它可以访问我在C++中开发的一个库。目前,它是非常基本的,因为这只是为了测试目的。在

在我的.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)就在同一个目录中。。我哪里出错了?在


Tags: 文件inpyselfinitliblinelibrary

热门问题