[CMake] SWIG python3

Matthias Fulz mfulz at olznet.de
Mon Mar 12 17:52:12 EDT 2012


Hi,

I'm trying basic examples for using SWIG to generate python extensions
for c++:

cmake_minimum_required(VERSION 2.8)

FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})

FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

SET(CMAKE_SWIG_FLAGS "")

SET_SOURCE_FILES_PROPERTIES(number.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(number.i PROPERTIES SWIG_FLAGS
"-includeall")
SWIG_ADD_MODULE(number python
  number.i number.hpp number.cpp)
SWIG_LINK_LIBRARIES(number ${PYTHON_LIBRARIES})

This CMakeLists.txt is working fine, but only for python2, when I try to
import it in python3, I'll receive the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "number.py", line 26, in <module>
    _number = swig_import_helper()
  File "number.py", line 22, in swig_import_helper
    _mod = imp.load_module('_number', fp, pathname, description)
ImportError: dynamic module does not define init function
(PyInit__number)

Could someone help me out here?

Thanks,

Matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120312/c58d78a1/attachment.pgp>


More information about the CMake mailing list