1

I included Qt 6.9.1 header files and pybind11/pybind11.h in a same file. but then I use python to build a package.(the compiler is MSVC2022 x64 and I only use CMake)

this is part of setup.py:

import os
import re
import subprocess
import sys
from time import gmtime, strftime, time
from pathlib import Path

from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext

# Convert distutils Windows platform specifiers to CMake -A arguments
PLAT_TO_CMAKE = {
    "win32": "Win32",
    "win-amd64": "x64",
    "win-arm32": "ARM",
    "win-arm64": "ARM64",
}

# A CMakeExtension needs a sourcedir instead of a file list.
# The name must be the _single_ output extension from the CMake build.
# If you need multiple extensions, see scikit-build.
class CMakeExtension(Extension):
    def __init__(self, name: str, sourcedir: str = "") -> None:
        super().__init__(name, sources=[])
        self.sourcedir = os.fspath(Path(sourcedir).resolve())


class CMakeBuild(build_ext):
    def build_extension(self, ext: CMakeExtension) -> None:
        # Must be in this form due to bug in .resolve() only fixed in Python 3.10+
        ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
        extdir = ext_fullpath.parent.resolve() / MODULE_NAME

        # Using this requires trailing slash for auto-detection & inclusion of
        # auxiliary "native" libs

        debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
        cfg = "Debug" if debug else "Release"

        # CMake lets you override the generator - we need to check this.
        # Can be set with Conda-Build, for example.
        cmake_generator = os.environ.get("CMAKE_GENERATOR", "")

        # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
        # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code
        # from Python.
        cmake_args = [
            f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
            f"-DPYTHON_EXECUTABLE={sys.executable}",
            f"-DCMAKE_BUILD_TYPE={cfg}",  # not used on MSVC, but no harm
            # "-C "
        ]
        build_args = []
        # Adding CMake arguments set as environment variable
        # (needed e.g. to build for ARM OSx on conda-forge)
        if "CMAKE_ARGS" in os.environ:
            cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]

        # In this example, we pass in the version to C++. You might not need to.
        cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"]
        
        if self.compiler.compiler_type != "msvc":
            # Using Ninja-build since it a) is available as a wheel and b)
            # multithreads automatically. MSVC would require all variables be
            # exported for Ninja to pick it up, which is a little tricky to do.
            # Users can override the generator with CMAKE_GENERATOR in CMake
            # 3.15+.
            if not cmake_generator or cmake_generator == "Ninja":
                try:
                    import ninja

                    ninja_executable_path = Path(ninja.BIN_DIR) / "ninja"
                    cmake_args += [
                        "-GNinja",
                        f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}",
                    ]
                except ImportError:
                    pass

        else:
            # Single config generators are handled "normally"
            single_config = any(x in cmake_generator for x in {"NMake", "Ninja"})

            # CMake allows an arch-in-generator style for backward compatibility
            contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})

            # Specify the arch if using MSVC generator, but only if it doesn't
            # contain a backward-compatibility arch spec already in the
            # generator name.
            if not single_config and not contains_arch:
                cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]

            # Multi-config generators have a different way to specify configs
            if not single_config:
                cmake_args += [
                    f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}"
                ]
                build_args += ["--config", cfg]

        if sys.platform.startswith("darwin"):
            # Cross-compile support for macOS - respect ARCHFLAGS if set
            archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
            if archs:
                cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]

        # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
        # across all generators.
        if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
            # self.parallel is a Python 3 only way to set parallel jobs by hand
            # using -j in the build_ext call, not supported by pip or PyPA-build.
            if hasattr(self, "parallel") and self.parallel:
                # CMake 3.12+ only.
                build_args += [f"-j{self.parallel}"]

        build_temp = Path(self.build_temp) / ext.name
        if not build_temp.exists():
            build_temp.mkdir(parents=True)

        subprocess.run(
            ["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True
        )
        subprocess.run(
            ["cmake", "--build", ".", *build_args], cwd=build_temp, check=True
        )



the binding file:


#include <UDFrameless.h> //the header file I included Qt library files
#include<pybind11/pybind11.h>
#include<pybind11/embed.h> //I tried PYBIND11_MODULE and it is also occurs errors
namespace py=pybind11;
PYBIND11_EMBEDDED_MODULE(UDFrameless, mod) {
    mod.doc() = "cxxtestpy module";
    // mod.def("setWindowEffect",&UDFrameless::setWindowEffect,py::arg("hwnd"),py::arg("key"),py::arg("enable"));

    
}

the error output:(It's in Chinese)

running build
running build_ext
-- G:/Qt/6.9.1/msvc2022_64/
-- pybind11 v3.0.1 
Using compatibility mode for Python, set PYBIND11_FINDPYTHON to NEW/OLD to silence this message
-- Configuring done (0.8s)
-- Generating done (0.1s)
-- Build files have been written to: E:/pybind-test/build/temp.win-amd64-cpython-312/Release/pybind-test
适用于 .NET Framework MSBuild 版本 17.14.18+a338add32

  cxxtest.cpp
  cxxtest.vcxproj -> E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\lib\Release\cxxtest.lib
  bindings.cpp
E:\Python312\include\object.h(352,23): error C2059: 语法错误:“;” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bindings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\Python312\include\object.h(352,23): error C2238: 意外的标记位于“;”之前 [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bindings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\detail\function_record_pyobject.h(86,7): error C2078: 初始值设定项太多 [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-tes
t\bindings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\detail\function_record_pyobject.h(91,8): error C2078: 初始值设定项太多 [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-tes
t\bindings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1394,20): error C2760: 语法错误: 此处出现意外的“++”;应为“,” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bin
dings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1394,22): error C2760: 语法错误: 此处出现意外的“]”;应为“;” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bind
ings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1394,22): error C3878: 语法错误:“expression-statement”后出现意外标记“]” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\p
ybind-test\bindings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1394,89): error C2760: 语法错误: 此处出现意外的“}”;应为“;” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bind
ings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1397,24): error C2760: 语法错误: 此处出现意外的“++”;应为“,” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bin
dings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1397,26): error C2760: 语法错误: 此处出现意外的“]”;应为“;” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bind
ings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1397,26): error C3878: 语法错误:“expression-statement”后出现意外标记“]” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\p
ybind-test\bindings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1397,77): error C2760: 语法错误: 此处出现意外的“}”;应为“;” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bind
ings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1401,20): error C2760: 语法错误: 此处出现意外的“++”;应为“,” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bin
dings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1401,22): error C2760: 语法错误: 此处出现意外的“]”;应为“;” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bind
ings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1401,22): error C3878: 语法错误:“expression-statement”后出现意外标记“]” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\p
ybind-test\bindings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1401,86): error C2760: 语法错误: 此处出现意外的“}”;应为“;” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bind
ings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1411,20): error C2760: 语法错误: 此处出现意外的“++”;应为“,” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bin
dings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1411,22): error C2760: 语法错误: 此处出现意外的“]”;应为“;” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bind
ings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1411,22): error C3878: 语法错误:“expression-statement”后出现意外标记“]” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\p
ybind-test\bindings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\pybind11\include\pybind11\pybind11.h(1411,37): error C2760: 语法错误: 此处出现意外的“}”;应为“;” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bind
ings\cxxtestpy.vcxproj]
  (编译源文件“../../../../../bindings/bindings.cpp”)

E:\pybind-test\bindings\bindings.cpp(8,1): error C2513: “std::array<PyModuleDef_Slot,5>”: 在“=”前没有声明变量 [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bindings\
cxxtestpy.vcxproj]
E:\pybind-test\bindings\bindings.cpp(8,1): error C2059: 语法错误:“(” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bindings\cxxtestpy.vcxproj]
E:\pybind-test\bindings\bindings.cpp(8,1): error C2143: 语法错误: 缺少“;”(在“}”的前面) [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bindings\cxxtestpy.vcxproj]
E:\pybind-test\bindings\bindings.cpp(8,1): error C2059: 语法错误:“return” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bindings\cxxtestpy.vcxproj]
E:\pybind-test\bindings\bindings.cpp(8,1): error C2059: 语法错误:“}” [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bindings\cxxtestpy.vcxproj]
E:\pybind-test\bindings\bindings.cpp(8,1): error C3861: “pybind11_init_cxxtestpy”: 找不到标识符 [E:\pybind-test\build\temp.win-amd64-cpython-312\Release\pybind-test\bindings\cxxtestpy.vc
xproj]

I want to solve the problem

1 Answer 1

0

update the pybind11 repository and this issue disappears.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.