C++: numpy/arrayobject.h: 没有这样的文件或目录 CMake VSCode
C++: numpy/arrayobject.h: No such file or directory CMake VSCode
我想在我的 C++ 脚本中包含 Python.h
和 numpy/arrayobject.h
。但是它无法打开这些源文件。
CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(myProj VERSION 0.1.0 DESCRIPTION "myProj")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(PythonLibs REQUIRED) <--- work
find_package(Python3 3.6 COMPONENTS Interpreter NumPy REQUIRED) <--- not work
include_directories(${PYTHON_INCLUDE_DIRS})
add_executable(myProj main.cc)
target_link_libraries(myProj ${PYTHON_LIBRARIES} Python3:NumPy)
错误
[cmake] CMake Error at CMakeLists.txt:9 (find_package):
[cmake] By not providing "FindPython3.cmake" in CMAKE_MODULE_PATH this project has
[cmake] asked CMake to find a package configuration file provided by "Python3", but
[cmake] CMake did not find one.
[cmake]
[cmake] Could not find a package configuration file provided by "Python3"
[cmake] (requested version 3.6) with any of the following names:
[cmake]
[cmake] Python3Config.cmake
[cmake] python3-config.cmake
[cmake]
[cmake] Add the installation prefix of "Python3" to CMAKE_PREFIX_PATH or set
[cmake] "Python3_DIR" to a directory containing one of the above files. If
[cmake] "Python3" provides a separate development package or SDK, be sure it has
[cmake] been installed.
NumPy 路径
(venv) cyan@linux01:~/TEMP$ python -c "import numpy; print(numpy.get_include())"
/home/cyan/venv/lib/python3.6/site-packages/numpy/core/include
问题
如何修改我的 CMakeLists.txt
以便在 C++ 中包含 header numpy/arrayobject.h
?
我没有看到很多关于 FindPython3
或 FindPython
的 CMake 3.0.0 文档,所以我不确定该模块是否包含在 CMake 3.12.0 之前。版本 3.12 是我在 cmake 文档中找到的第一个版本。
最有可能的是你只需要更改为使用
cmake_minimum_required(VERSION 3.12.0)
更新您的 CMake 版本可能是最简单的解决方案,但同样您可能有充分的理由限制版本并且仅仅告诉您更新并不是一个很好的解决方案。
另一个黑客解决方案是使用来自 Python_INCLUDE_DIRS 或 Python_LIBRARIES 的路径之一从那里做一些相对路径。像
set(numpy_INCLUDE_DIR "${Python_INCLUDE_DIR}/../site-packages/numpy
/core/include")
include_directories(${Python_INCLUDE_DIRS} ${numpy_INCLUDE_DIR})
然而,这假设您的 python 目录被设置为好像它们来自 python 发行版,并且反过来假设每个使用它的人也有一个具有相同文件结构的发行版。
我想在我的 C++ 脚本中包含 Python.h
和 numpy/arrayobject.h
。但是它无法打开这些源文件。
CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(myProj VERSION 0.1.0 DESCRIPTION "myProj")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(PythonLibs REQUIRED) <--- work
find_package(Python3 3.6 COMPONENTS Interpreter NumPy REQUIRED) <--- not work
include_directories(${PYTHON_INCLUDE_DIRS})
add_executable(myProj main.cc)
target_link_libraries(myProj ${PYTHON_LIBRARIES} Python3:NumPy)
错误
[cmake] CMake Error at CMakeLists.txt:9 (find_package):
[cmake] By not providing "FindPython3.cmake" in CMAKE_MODULE_PATH this project has
[cmake] asked CMake to find a package configuration file provided by "Python3", but
[cmake] CMake did not find one.
[cmake]
[cmake] Could not find a package configuration file provided by "Python3"
[cmake] (requested version 3.6) with any of the following names:
[cmake]
[cmake] Python3Config.cmake
[cmake] python3-config.cmake
[cmake]
[cmake] Add the installation prefix of "Python3" to CMAKE_PREFIX_PATH or set
[cmake] "Python3_DIR" to a directory containing one of the above files. If
[cmake] "Python3" provides a separate development package or SDK, be sure it has
[cmake] been installed.
NumPy 路径
(venv) cyan@linux01:~/TEMP$ python -c "import numpy; print(numpy.get_include())"
/home/cyan/venv/lib/python3.6/site-packages/numpy/core/include
问题
如何修改我的 CMakeLists.txt
以便在 C++ 中包含 header numpy/arrayobject.h
?
我没有看到很多关于 FindPython3
或 FindPython
的 CMake 3.0.0 文档,所以我不确定该模块是否包含在 CMake 3.12.0 之前。版本 3.12 是我在 cmake 文档中找到的第一个版本。
最有可能的是你只需要更改为使用
cmake_minimum_required(VERSION 3.12.0)
更新您的 CMake 版本可能是最简单的解决方案,但同样您可能有充分的理由限制版本并且仅仅告诉您更新并不是一个很好的解决方案。
另一个黑客解决方案是使用来自 Python_INCLUDE_DIRS 或 Python_LIBRARIES 的路径之一从那里做一些相对路径。像
set(numpy_INCLUDE_DIR "${Python_INCLUDE_DIR}/../site-packages/numpy
/core/include")
include_directories(${Python_INCLUDE_DIRS} ${numpy_INCLUDE_DIR})
然而,这假设您的 python 目录被设置为好像它们来自 python 发行版,并且反过来假设每个使用它的人也有一个具有相同文件结构的发行版。