我无法通过 CMake 和 Swig for Python3 为我的 C 库构建 Python 包装器模块。Python2.x 一切正常,但看起来 CMake 找不到 Python3。我已经环顾四周并尝试了几件事。
例如,我的python
可执行文件链接到 Python3,当我阅读 CMake 时会首先找到这个版本。
请在此处查看 SWIG 部分CMakeLists.txt
:
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
FIND_PACKAGE(PythonInterp 3)
FIND_PACKAGE(PythonLibs 3)
FIND_PATH(PYTHON_INCLUDE_PATH Python.h
/usr/include
/usr/local/include)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
SET(CMAKE_SWIG_FLAGS "")
SET_SOURCE_FILES_PROPERTIES(kissCT3.i PROPERTIES CPLUSPLUS ON)
#SET_SOURCE_FILES_PROPERTIES(kissCT3.i PROPERTIES SWIG_FLAGS "-includeall -py3")
SWIG_ADD_MODULE(kissCT3 python kissCT3.i)
SWIG_LINK_LIBRARIES(kissCT3 libct2d matio kissfft ${PYTHON_LIBRARIES})
不幸的是,调用cmake后的输出显示只找到了python2.7:
-- Found SWIG: /usr/bin/swig2.0 (found version "2.0.4")
-- Found PythonInterp: /usr/bin/python2.7 (Required is at least version "3")
-- Found PythonLibs: /usr/lib/libpython2.7.so (Required is at least version "3")
-- Configuring done
-- Generating done