I'm trying to build python extension. I've create simple library that export single function. It's just a single file - testlib.c that implements function called 'apicall'. Then I create SWIG interface file:
%module testlibpy
void apicall(const char* message);
Then I use this command to generate interface: swig -python -py3 -modern testlibpy.i
My setup.py looks like this:
from distutils.core import setup, Extension
example_module = Extension('_testlibpy',
sources=['testlibpy_wrap.c', 'testlib.c'],)
setup (name = 'testlibpy',
version = '0.1',
author = "SWIG Docs",
description = """Simple swig example from docs""",
ext_modules = [example_module],
py_modules = ["testlibpy"],
)
I'm building extension using command: python3.4 ./setup.py build_ext --inplace
. Everything works fine. When I'm trying to import my new extension from python3.4 command-line, I've get following error:
Python 3.4.2 (default, Feb 18 2015, 04:50:08)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import testlibpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../sandbox/swigtest/testlibpy.py", line 24, in <module>
_testlibpy = swig_import_helper()
File ".../sandbox/swigtest/testlibpy.py", line 20, in swig_import_helper
_mod = imp.load_module('_testlibpy', fp, pathname, description)
File ".../swt/install/python-3.4.2/lib/python3.4/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
ImportError: .../sandbox/swigtest/_testlibpy.cpython-34m.so: undefined symbol: PyCObject_FromVoidPtr
>>>
Everything works fine for other python versions - 2.7 and 3.0. SWIG Version 1.3.40