我正在尝试使用/学习CMake将Python嵌入到使用Qt的C ++应用程序中。
我正在使用FIND_PACKAGE试图获得非系统软件包安装(Anaconda Python 2.7.9)。我无法让编译器看到除系统安装之外的任何版本(版本2.7.5)。 / p>
我的CMakeLists.txt是:
#Minimum CMAKE version
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
#Name the project
PROJECT(embedpython)
#Set the version number
SET(embedpython_VERSION_MAJOR 0)
SET(embedpython_VERSION_MINOR 1)
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
FIND_PACKAGE(Qt4 4.8.6 REQUIRED QtGui QtCore)
QT4_WRAP_CPP(embedpython_HEADERS_MOC ${embedpython_HEADERS})
message(status "QT FOUND: ${Qt4_FOUND}")
FIND_PACKAGE(PythonLibs 2.7.9 REQUIRED)
message(status "libs found: ${PYTHONLIBS_FOUND}")
MESSAGE(STATUS "PYTHON_LIBRARIES: ${PYTHON_LIBRARIES}")
MESSAGE(STATUS "PYTHON_INCLUDE_PATH: ${PYTHON_INCLUDE_PATH}")
MESSAGE(STATUS "PYTHONLIBS_VERSION: ${PYTHONLIBS_VERSION_STRING}")
MESSAGE(STATUS "PYTHON_INCLUDE_DIRS: ${PYTHON_INCLUDE_DIRS}")
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
SET(embedpython_SOURCES
main.cpp
mainwindow.cpp
pythonutilsimpl.cpp
ipcepythonrunner.cpp)
SET(embedpython_HEADERS
mainwindow.h
pythonutilsimpl.h
ipcepythonutils.h
ipcepythonrunner.h)
ADD_EXECUTABLE(embedpython ${embedpython_SOURCES} ${embedpython_HEADERS_MOC})
TARGET_LINK_LIBRARIES(embedpython ${QT_LIBRARIES} ${PYTHON_LIBRARIES})
哪个输出:
cmpt:build user$ /Applications/CMake.app/Contents/bin/cmake .. && make
statusQT FOUND: TRUE
statuslibs found: TRUE
-- PYTHON_LIBRARIES: /home/me/anaconda/lib/libpython2.7.dylib
-- PYTHON_INCLUDE_PATH: /home/me/anaconda/include/python2.7
-- PYTHONLIBS_VERSION: 2.7.9
-- PYTHON_INCLUDE_DIRS: /home/me/anaconda/include/python2.7
-- Configuring done
-- Generating done
-- Build files have been written to: /home/me/Desktop/EmbedPython/build
Scanning dependencies of target embedpython_automoc
[ 16%] Automatic moc for target embedpython
Generating moc_mainwindow.cpp
[ 16%] Built target embedpython_automoc
Scanning dependencies of target embedpython
[ 33%] Building CXX object CMakeFiles/embedpython.dir/main.cpp.o
[ 50%] Building CXX object CMakeFiles/embedpython.dir/mainwindow.cpp.o
[ 66%] Building CXX object CMakeFiles/embedpython.dir/pythonutilsimpl.cpp.o
[ 83%] Building CXX object CMakeFiles/embedpython.dir/ipcepythonrunner.cpp.o
[100%] Building CXX object CMakeFiles/embedpython.dir/embedpython_automoc.cpp.o
Linking CXX executable embedpython
[100%] Built target embed python
使用ccmake,我设置了PYTHON_INCLUDE_DIR和PYTHON_LIBRARY,以便FIND_PACKAGE成功找到Python 2.7.9。
在C ++中,我有一个调试来打印python版本和路径。没有失败,这将返回Python 2.7.5。在CMake文件中需要什么来获取我所追求的PATH版本的Python?