From 78f3828bafe06227d0afbd4147676bf2ab89a95f Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Fri, 10 Oct 2025 20:12:02 +0800 Subject: [PATCH] update --- .../guan_cpp_project/pyproject.toml | 3 +++ .../guan_cpp_project/setup.py | 20 +++++++++++++++++++ .../guan_cpp_project/src/cpp/main.cpp | 10 ++++++++++ .../guan_cpp_project/src/guan_cpp/__init__.py | 1 + 4 files changed, 34 insertions(+) create mode 100644 2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/pyproject.toml create mode 100644 2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/setup.py create mode 100644 2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/cpp/main.cpp create mode 100644 2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/guan_cpp/__init__.py diff --git a/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/pyproject.toml b/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/pyproject.toml new file mode 100644 index 0000000..61c68c9 --- /dev/null +++ b/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools", "wheel", "pybind11"] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/setup.py b/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/setup.py new file mode 100644 index 0000000..8640d11 --- /dev/null +++ b/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/setup.py @@ -0,0 +1,20 @@ +from setuptools import setup, Extension +import pybind11 + +ext_modules = [ + Extension( + "guan_cpp.guan_cpp_module", # 包名.模块名 + ["src/cpp/main.cpp"], # C++ 源文件列表 + include_dirs=[pybind11.get_include()], # pybind11头文件 + language="c++", # 指定语言为 C++ + extra_link_args=["-static-libstdc++"], # 可选静态链接 + ), +] + +setup( + name="guan_cpp", # 项目的名称(用于 pip install) + version="0.0.1", # 版本号 + package_dir={"": "src"}, # ​​指定 Python 包的根目录​​ + packages=["guan_cpp"], # 包的名称(用于 import) + ext_modules=ext_modules, # 指定 C++ 扩展模块 +) \ No newline at end of file diff --git a/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/cpp/main.cpp b/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/cpp/main.cpp new file mode 100644 index 0000000..7fe8d77 --- /dev/null +++ b/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/cpp/main.cpp @@ -0,0 +1,10 @@ +#include + +int add(int a, int b) { + return a + b; +} + +PYBIND11_MODULE(guan_cpp_module, m) { + m.doc() = "My C++ extension for Python"; + m.def("add", &add, "A function that adds two numbers"); +} diff --git a/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/guan_cpp/__init__.py b/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/guan_cpp/__init__.py new file mode 100644 index 0000000..c557576 --- /dev/null +++ b/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/guan_cpp/__init__.py @@ -0,0 +1 @@ +from .guan_cpp_module import * \ No newline at end of file