pybind / pybind/scikit_build_example
How to build with third-party dependencies
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 148
- Forks
- 39
- Avg merge
- 8d 2h
- Merged PRs (30d)
- 1
Description
Hello, everyone
First of all, thank you for providing this build example.
To give some context for my question. I aim to create a pybind11 binding for one C++ function to enable its invocation from Python code. But this function dependes on a third-party library called OpenCASCADE.
I'm building on a windows OS. I have cloned this repository and tried to add a simple function into the main.cpp to test the build. I have added the following lines:
main.cpp:
#include <TopoDS_Shape.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
TopoDS_Shape makeBox(float length, float width, float height){
return BRepPrimAPI_MakeBox(length, width, height).Shape();
}
m.def("make_box", &makeBox, "A function that returns a TopoDS_Shape");
And I have also added these lines into the CmakeLists.txt to take into account the OpenCASCADE dependecy:
CmakeLists.txt:
set(OpenCASCADE_DIR "C:/Program Files/OCCT/opencascade-install/cmake")
# OpenCascade
find_package(OpenCASCADE)
# Configure C++ compiler's includes dir
include_directories(SYSTEM ${OpenCASCADE_INCLUDE_DIR})
# Add linker options
foreach(LIB ${OpenCASCADE_LIBRARIES})
# TODO: add only optimized build in production
#target_link_libraries(_core PUBLIC debug ${OpenCASCADE_LIBRARY_DIR}d/${LIB}.lib)
target_link_libraries(_core PUBLIC optimized ${OpenCASCADE_LIBRARY_DIR}/${LIB}.lib)
endforeach(LIB)
set_property(TARGET _core PROPERTY VS_DEBUGGER_ENVIRONMENT "PATH=$<$<CONFIG:DEBUG>:${OpenCASCADE_BINARY_DIR}d>$<$<NOT:$<CONFIG:DEBUG>>:${OpenCASCADE_BINARY_DIR}>;%PATH%")
When I run pip install ./scikit_build_example I have a successful installation, but then when I try to import scikit_build_example I get the following error:
module = self._system_import(name, *args, **kwargs)
ImportError: DLL load failed while importing _core: The specified module could not be found.
Searching about this error I've found some people saying that to solve I could use the following code:
import os
os.add_dll_directory()
So I've tried referencing my opencascade installation folder, that on my machine is on the path: "C:/Program Files/OCCT/opencascade-install/win64/vc14/bin"
It worked. I would like to know if is there some way to specify this path in the moment of the build. If it should be specified in the CmakeLists.txt or in other file like pyproject.toml.
Any insights or examples on this matter would be highly appreciated!
Thank you very much for the attention
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with main.cpp and CMakeLists.txt, then inspect pyproject.toml for how the extension is built and installed. Reproduce the Windows workflow with pip install ./scikit_build_example followed by importing scikit_build_example. Done means the OpenCASCADE runtime dependency is handled by the package so the import works without os.add_dll_directory().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100