CMake"pyembree"的生成帮助



我正在寻找使用CMake for Windows从源代码构建pyembree的帮助。GitHub上列出了这个问题历史的更多细节。刚刚删除了Windows对conda-forge上pyembree的支持,所以如果能提供任何帮助,我们将不胜感激!

安装说明

系统

测试日期:

操作系统:Windows 10 x64 Professional,1909版本Python:3.8.10

步骤

  1. 安装Microsoft Visual C++14.X和Windows 10 SDK。这些是构建cython代码所必需的

(注意:Microsoft Visual Studio的版本与Microsoft Visual C++的版本不同。Visual Studio 2015、2017和2019都有MSVCv14X生成工具。在撰写本文时,使用安装Visual Studio 2019生成工具

MSVCv142 - VS 2019 C++ x64/x86 build toolsWindows 10 SDK (10.0.18362.0)

组件就足够了(如果安装Visual Studio 2019,请选择Desktop development with C++工作负载)

  1. 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
  1. 安装embree2 64-bit
vcpkg install embree2:x64-windows

注意:到目前为止,pyembree仍然依赖于Embree 2,并且尚未针对Embree 3进行更新。

  1. 安装cmake。

  2. 创建项目文件夹并使用venv初始化虚拟环境(使用Python 3.6 - 3.8)。在本例中,选择了Python 3.8.5 x64-bit,因为它是Miniconda py38_4.9.2中使用的Python版本。

  3. 安装以下软件包:

py -m pip install numpy cython cmake ninja scikit-build wheel setuptools pyvista pykdtree
  1. 将以下cmake模块添加到系统cmake模件文件夹中(例如C:Program FilesCMakesharecmake-3.21Modules)。

  2. 导航到<virtual environment folder>Libsite-packages并克隆pyembreerepo:

git clone https://github.com/scopatz/pyembree.git
  1. 将目录更改为pyembree文件夹并创建以下顶级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})
  1. 移动到子文件夹pyembree并创建以下子级别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)

相应地替换CCD_ 21(例如C:/Program Files/Python38)和CCD_。

  1. 移回顶级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
)
  1. pyembree中的每个*.pyx*.pxd文件的顶部添加以下行:
# distutils: language=c++
  1. 通过从顶级pyembree文件夹运行以下程序来构建和安装pyembree
py setup.py build
py setup.py install
  1. 最后,安装rtreetrimesh
py -m pip install rtree trimesh

当前的挑战

我被困在py setup.py build

  1. 当前,我需要将embree标头和库(.lib.dll)复制并粘贴到源文件夹(<virtual environment folder>/Lib/site-packages/pyembree)和生成的构建文件夹(<virtual environment folder>Libsite-packagespyembree_skbuildwin-amd64-3.8cmake-buildpyembree)

是否有可以在CMake中使用的复制文件命令?

  1. 运行py setup.py build时,我会得到__imp_rtcMapBuffer__imp_rtc_NewTriangleMesh__imp_rtcUnmapBufferLNK201: unresolved external symbol链接器错误。不过,我相信__imp_是一个DLL结构,它只适用于C语言和共享库(而不是静态库),所以我有点困惑

如果对此错误有任何帮助,我们也将不胜感激!

Creating library _skbuildwin-amd64-3.8setuptoolstemp.win-amd64-3.8Releasepyembreemesh_construction.cp38-win_amd64.lib and object _skbuildwin-amd64-3.8setuptoolstemp.win-amd64-3.8Releasepyembreemesh_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
_skbuildwin-amd64-3.8setuptoolslib.win-amd64-3.8pyembreemesh_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实际上不是必需的。有关完整说明,请参阅我在不带Conda#468的Windows上安装pyembree的解决方案。

相关内容

  • 没有找到相关文章

最新更新