Creating a C++ Wrapper in Python using .dylib -


i'm trying develop wrapper in python can access library have developed in c++. @ minute, basic, testing purposes.

in .h file have following:

#include <iostream>  class foo {    public:      void bar() {         std::cout << "hello world";     } }; 

and in python file call using following:

from ctypes import cdll   lib = cdll.loadlibary('./libfoo.1.dylib')  class foo(object): def __init__(self):     self.obj = lib.foo_new();  def bar(self):     lib.foo_bar(self.obj)  f = foo(); f.bar(); 

i have created .dylib since don't believe possible create shared library in gcc on mac, but, wrong. i'm getting following errors:

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

but found, , library (.dylib) infact in same directory.. going wrong?

the ctypes library doesn't know c++, need write shared library in c if want use ctypes.

you can @ http://www.swig.org instead, can hook shared library written in c++.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -