`pyembree` 的 CMake 构建帮助
CMake Build Help for `pyembree`
我正在寻求使用 CMake 为 Windows 从源代码构建 pyembree
的帮助。 here on GitHub 列出了有关此问题历史的更多详细信息。 Windows conda-forge 上对 pyembree
的支持刚刚被删除,因此我们将不胜感激任何可以提供的帮助!
安装说明
系统
测试于:
OS: Windows 10 x64 专业版,内部版本 1909
Python: 3.8.10
步骤
- 安装Microsoft Visual C++ 14.X and Windows 10 SDK。这些是构建
cython
代码所必需的。
(NOTE: The version of Microsoft Visual Studio is not the same as the version of Microsoft Visual C++. Visual Studio 2015, 2017, and 2019 all have MSVCv14X build tools. At the time of this writing, installing the Visual Studio 2019 Build Tools with
MSVCv142 - VS 2019 C++ x64/x86 build tools
and
Windows 10 SDK (10.0.18362.0)
components will suffice (select the Desktop development with C++
Workload if installing Visual Studio 2019).
- 在
C:\vcpkg
中安装 vcpkg 并将路径添加到您的 System Environment Variables
:
C:
mkdir vcpkg
cd C:\vcpkg
git clone https://github.com/Microsoft/vcpkg.git
bootstrap-vcpkg.bat
vcpkg integrate install
- 安装
embree2 64-bit
:
vcpkg install embree2:x64-windows
NOTE: To date, pyembree still relies on Embree 2 and has not been updated for Embree 3.
安装cmake.
创建项目文件夹并使用 venv
(使用 Python 3.6 - 3.8
)初始化虚拟环境。在此示例中,选择了 Python 3.8.5 x64-bit
,因为它是 Miniconda py38_4.9.2
.
中使用的 Python 版本
安装以下软件包:
py -m pip install numpy cython cmake ninja scikit-build wheel setuptools pyvista pykdtree
将以下 cmake modules 添加到您的系统 cmake 模块文件夹(例如 C:\Program Files\CMake\share\cmake-3.21\Modules\
)。
导航至 <virtual environment folder>\Lib\site-packages
并克隆 pyembree
存储库:
git clone https://github.com/scopatz/pyembree.git
- 将目录更改为
pyembree
文件夹并创建以下内容 top-level CMakeLists.txt
cmake_minimum_required(VERSION 3.21.0)
project(pyembree
VERSION 0.1.6
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED True)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake")
find_package(PythonExtensions REQUIRED)
find_package(Cython REQUIRED)
find_package(embree 2 CONFIG REQUIRED)
add_subdirectory(${PROJECT_NAME})
- 移动到子文件夹
pyembree
并创建以下 sub-level CMakeLists.txt
:
add_cython_target(mesh_construction.pyx CXX)
add_cython_target(rtcore_scene.pyx CXX)
add_cython_target(rtcore.pyx CXX)
add_cython_target(triangles.pyx CXX)
add_library(${PROJECT_NAME} STATIC ${mesh_construction} ${rtcore_scene} ${rtcore} ${triangles})
target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${PROJECT_NAME}
PUBLIC "<system python path>/include"
PUBLIC "C:/vcpkg/installed/x64-windows/include/embree2"
PUBLIC "<virtual environment folder>/Lib/site-packages/numpy/core/include"
)
target_link_directories(${PROJECT_NAME}
PUBLIC "<system python path>/libs"
PUBLIC "C:/vcpkg/installed/x64-windows/lib"
PUBLIC "C:/vcpkg/installed/x64-windows/bin"
PUBLIC "<virtual environment folder>/Lib/site-packages/numpy/core/lib"
)
target_link_libraries(${PROJECT_NAME}
embree
)
python_extension_module(${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib)
相应地替换 <system python path>
(例如 C:/Program Files/Python38
)和 <virtual environment folder>
。
- 返回 top-level
pyembree
文件夹并创建以下 setup.py
文件:
from setuptools import find_packages
from skbuild import setup
import numpy as np
from Cython.Build import cythonize
include_path = [np.get_include()]
ext_modules = cythonize('pyembree/*.pyx', language_level=3, include_path=include_path)
for ext in ext_modules:
ext.include_dirs = include_path
ext.libraries = [
"C:/vcpkg/installed/x86-windows/lib/embree",
"C:/vcpkg/installed/x86-windows/lib/tbb",
"C:/vcpkg/installed/x86-windows/lib/tbbmalloc",
"C:/vcpkg/installed/x86-windows/lib/tbbmalloc_proxy",
]
setup(
name="pyembree",
version='0.1.6',
ext_modules=ext_modules,
zip_safe=False,
packages=find_packages(),
include_package_data=True
)
- 将以下行添加到
pyembree
中每个 *.pyx
和 *.pxd
文件的顶部:
# distutils: language=c++
- 通过 运行 top-level
pyembree
文件夹中的以下内容构建并安装 pyembree
:
py setup.py build
py setup.py install
- 最后,安装
rtree
和trimesh
:
py -m pip install rtree trimesh
当前挑战
我卡在了 py setup.py build
。
- 目前,我需要将
embree
headers 和库(.lib
和 .dll
)复制并粘贴到源文件夹 (<virtual environment folder>/Lib/site-packages/pyembree
)并生成构建文件夹 (<virtual environment folder>\Lib\site-packages\pyembree\_skbuild\win-amd64-3.8\cmake-build\pyembree
)
是否有我可以在 CMake 中使用的复制文件命令?
- 当 运行
py setup.py build
时,我得到 LNK201: unresolved external symbol
__imp_rtcMapBuffer
、__imp_rtc_NewTriangleMesh
和 __imp_rtcUnmapBuffer
的链接器错误。我相信 __imp_
是一个 DLL 构造,它只适用于 C-Language 和共享库(不是静态库),所以我有点困惑。
对于此错误的任何帮助也将不胜感激!
Creating library _skbuild\win-amd64-3.8\setuptools\temp.win-amd64-3.8\Release\pyembree\mesh_construction.cp38-win_amd64.lib and object _skbuild\win-amd64-3.8\setuptools\temp.win-amd64-3.8\Release\pyembree\mesh_construction.cp38-win_amd64.exp
mesh_construction.obj : error LNK2001: unresolved external symbol __imp_rtcMapBuffer
mesh_construction.obj : error LNK2001: unresolved external symbol __imp_rtcNewTriangleMesh
mesh_construction.obj : error LNK2001: unresolved external symbol __imp_rtcUnmapBuffer
_skbuild\win-amd64-3.8\setuptools\lib.win-amd64-3.8\pyembree\mesh_construction.cp38-win_amd64.pyd : fatal error LNK1120: 3 unresolved externals
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe' failed with exit status 1120
实际上不需要CMake。有关完整说明,请参阅我在 Install pyembree
on Windows without Conda #468.
上的解决方案
我正在寻求使用 CMake 为 Windows 从源代码构建 pyembree
的帮助。 here on GitHub 列出了有关此问题历史的更多详细信息。 Windows conda-forge 上对 pyembree
的支持刚刚被删除,因此我们将不胜感激任何可以提供的帮助!
安装说明
系统
测试于:
OS: Windows 10 x64 专业版,内部版本 1909 Python: 3.8.10
步骤
- 安装Microsoft Visual C++ 14.X and Windows 10 SDK。这些是构建
cython
代码所必需的。
(NOTE: The version of Microsoft Visual Studio is not the same as the version of Microsoft Visual C++. Visual Studio 2015, 2017, and 2019 all have MSVCv14X build tools. At the time of this writing, installing the Visual Studio 2019 Build Tools with
MSVCv142 - VS 2019 C++ x64/x86 build tools
andWindows 10 SDK (10.0.18362.0)
components will suffice (select the
Desktop development with C++
Workload if installing Visual Studio 2019).
- 在
C:\vcpkg
中安装 vcpkg 并将路径添加到您的System Environment Variables
:
C:
mkdir vcpkg
cd C:\vcpkg
git clone https://github.com/Microsoft/vcpkg.git
bootstrap-vcpkg.bat
vcpkg integrate install
- 安装
embree2 64-bit
:
vcpkg install embree2:x64-windows
NOTE: To date, pyembree still relies on Embree 2 and has not been updated for Embree 3.
安装cmake.
创建项目文件夹并使用
中使用的 Python 版本venv
(使用Python 3.6 - 3.8
)初始化虚拟环境。在此示例中,选择了Python 3.8.5 x64-bit
,因为它是Miniconda py38_4.9.2
.安装以下软件包:
py -m pip install numpy cython cmake ninja scikit-build wheel setuptools pyvista pykdtree
将以下 cmake modules 添加到您的系统 cmake 模块文件夹(例如
C:\Program Files\CMake\share\cmake-3.21\Modules\
)。导航至
<virtual environment folder>\Lib\site-packages
并克隆pyembree
存储库:
git clone https://github.com/scopatz/pyembree.git
- 将目录更改为
pyembree
文件夹并创建以下内容 top-levelCMakeLists.txt
cmake_minimum_required(VERSION 3.21.0)
project(pyembree
VERSION 0.1.6
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED True)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake")
find_package(PythonExtensions REQUIRED)
find_package(Cython REQUIRED)
find_package(embree 2 CONFIG REQUIRED)
add_subdirectory(${PROJECT_NAME})
- 移动到子文件夹
pyembree
并创建以下 sub-levelCMakeLists.txt
:
add_cython_target(mesh_construction.pyx CXX)
add_cython_target(rtcore_scene.pyx CXX)
add_cython_target(rtcore.pyx CXX)
add_cython_target(triangles.pyx CXX)
add_library(${PROJECT_NAME} STATIC ${mesh_construction} ${rtcore_scene} ${rtcore} ${triangles})
target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${PROJECT_NAME}
PUBLIC "<system python path>/include"
PUBLIC "C:/vcpkg/installed/x64-windows/include/embree2"
PUBLIC "<virtual environment folder>/Lib/site-packages/numpy/core/include"
)
target_link_directories(${PROJECT_NAME}
PUBLIC "<system python path>/libs"
PUBLIC "C:/vcpkg/installed/x64-windows/lib"
PUBLIC "C:/vcpkg/installed/x64-windows/bin"
PUBLIC "<virtual environment folder>/Lib/site-packages/numpy/core/lib"
)
target_link_libraries(${PROJECT_NAME}
embree
)
python_extension_module(${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib)
相应地替换 <system python path>
(例如 C:/Program Files/Python38
)和 <virtual environment folder>
。
- 返回 top-level
pyembree
文件夹并创建以下setup.py
文件:
from setuptools import find_packages
from skbuild import setup
import numpy as np
from Cython.Build import cythonize
include_path = [np.get_include()]
ext_modules = cythonize('pyembree/*.pyx', language_level=3, include_path=include_path)
for ext in ext_modules:
ext.include_dirs = include_path
ext.libraries = [
"C:/vcpkg/installed/x86-windows/lib/embree",
"C:/vcpkg/installed/x86-windows/lib/tbb",
"C:/vcpkg/installed/x86-windows/lib/tbbmalloc",
"C:/vcpkg/installed/x86-windows/lib/tbbmalloc_proxy",
]
setup(
name="pyembree",
version='0.1.6',
ext_modules=ext_modules,
zip_safe=False,
packages=find_packages(),
include_package_data=True
)
- 将以下行添加到
pyembree
中每个*.pyx
和*.pxd
文件的顶部:
# distutils: language=c++
- 通过 运行 top-level
pyembree
文件夹中的以下内容构建并安装pyembree
:
py setup.py build
py setup.py install
- 最后,安装
rtree
和trimesh
:
py -m pip install rtree trimesh
当前挑战
我卡在了 py setup.py build
。
- 目前,我需要将
embree
headers 和库(.lib
和.dll
)复制并粘贴到源文件夹 (<virtual environment folder>/Lib/site-packages/pyembree
)并生成构建文件夹 (<virtual environment folder>\Lib\site-packages\pyembree\_skbuild\win-amd64-3.8\cmake-build\pyembree
)
是否有我可以在 CMake 中使用的复制文件命令?
- 当 运行
py setup.py build
时,我得到LNK201: unresolved external symbol
__imp_rtcMapBuffer
、__imp_rtc_NewTriangleMesh
和__imp_rtcUnmapBuffer
的链接器错误。我相信__imp_
是一个 DLL 构造,它只适用于 C-Language 和共享库(不是静态库),所以我有点困惑。
对于此错误的任何帮助也将不胜感激!
Creating library _skbuild\win-amd64-3.8\setuptools\temp.win-amd64-3.8\Release\pyembree\mesh_construction.cp38-win_amd64.lib and object _skbuild\win-amd64-3.8\setuptools\temp.win-amd64-3.8\Release\pyembree\mesh_construction.cp38-win_amd64.exp
mesh_construction.obj : error LNK2001: unresolved external symbol __imp_rtcMapBuffer
mesh_construction.obj : error LNK2001: unresolved external symbol __imp_rtcNewTriangleMesh
mesh_construction.obj : error LNK2001: unresolved external symbol __imp_rtcUnmapBuffer
_skbuild\win-amd64-3.8\setuptools\lib.win-amd64-3.8\pyembree\mesh_construction.cp38-win_amd64.pyd : fatal error LNK1120: 3 unresolved externals
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe' failed with exit status 1120
实际上不需要CMake。有关完整说明,请参阅我在 Install pyembree
on Windows without Conda #468.