Код: Выделить всё
pybind11-example/
├── .venv/...
├── tests/...
├── src/
│ ├── example/
│ │ ├── __init__.py # Python package initialization
│ │ ├── example.pyi # Package type hinting
│ │ └── CMakeLists.txt # Package-specific CMake config
│ ├── mylib/
│ │ ├── CMakeLists.txt # Library-specific CMake config
│ │ ├── mylib.cpp # Shared library implementation
│ │ └── mylib.h # Shared library header with exports
│ └── example.cpp # C++ source with pybind11 bindings
├── extern/
│ └── pybind11/... # pybind11 submodule
├── CMakeLists.txt # Main CMake build configuration
└── pyproject.toml # Python project configuration
Код: Выделить всё
example/
├── __pycache__/...
├── __init__.py
├── CMakeLists.txt
├── example.cpython-314-x86_64-linux-gnu.so
├── example.pyi
└── libmylib.so
Код: Выделить всё
install(FILES
__init__.py
example.pyi
DESTINATION example
)
Код: Выделить всё
cmake_minimum_required(VERSION 3.18...4.0)
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)
set(PYBIND11_FINDPYTHON ON)
add_subdirectory(extern/pybind11)
add_subdirectory(src/mylib)
add_subdirectory(src/example)
target_compile_definitions(mylib PRIVATE BUILDING_MYLIB)
set_target_properties(mylib PROPERTIES
RUNTIME_OUTPUT_DIRECTORY $
)
pybind11_add_module(example src/example.cpp)
target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(example PRIVATE mylib)
if(NOT WIN32)
set_target_properties(example PROPERTIES
INSTALL_RPATH "$ORIGIN"
BUILD_WITH_INSTALL_RPATH TRUE
)
endif()
# Install Python files
install(TARGETS example
LIBRARY DESTINATION example
)
# Install library files
install(TARGETS mylib
RUNTIME DESTINATION example
LIBRARY DESTINATION example
)
Код: Выделить всё
[project]
name = "example"
version = "0.0.1"
[build-system]
requires = ["scikit-build-core", "pybind11"]
build-backend = "scikit_build_core.build"
Изменить:
Я заметил в журнале установки pip следующие строки:
Код: Выделить всё
-- Build files have been written to: /tmp/tmp5inwaohg/build
*** Building project with Ninja...
[1/4] Building CXX object src/mylib/CMakeFiles/mylib.dir/mylib.cpp.o
[2/4] Linking CXX shared library src/mylib/libmylib.so
[3/4] Building CXX object CMakeFiles/example.dir/src/example.cpp.o
[4/4] Linking CXX shared module example.cpython-314-x86_64-linux-gnu.so
*** Installing project into wheel...
-- Install configuration: "Release"
-- Installing: /tmp/tmp5inwaohg/wheel/platlib/example/__init__.py
-- Installing: /tmp/tmp5inwaohg/wheel/platlib/example/example.pyi
-- Installing: /tmp/tmp5inwaohg/wheel/platlib/example/example.cpython-314-x86_64-linux-gnu.so
-- Installing: /tmp/tmp5inwaohg/wheel/platlib/example/libmylib.so
*** Making wheel...
*** Created example-0.0.1-cp314-cp314-linux_x86_64.whl
Building wheel for example (pyproject.toml) ... done
Подробнее здесь: https://stackoverflow.com/questions/797 ... on-package
Мобильная версия