I have a simple test function on C++:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <locale.h>
#include <wchar.h>char fun() {printf( "%i", 12 );return 'y';
}
compiling:
gcc -o test.so -shared -fPIC test.cpp
and using it in python with ctypes:
from ctypes import cdll
from ctypes import c_char_plib = cdll.LoadLibrary('test.so')
hello = lib.fun
hello.restype = c_char_pprint('res', hello())
but then I get an error:
Traceback (most recent call last): File "./sort_c.py", line 10, in <module>hello = lib.fun File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 366, in __getattr__func = self.__getitem__(name) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 371, in __getitem__func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x100979b40, fun): symbol not found
Where is a problem?
using:
Mac Os X 10.7.5 and Python 2.7