我正在编写一个代码来从 c++ 编辑 Sqlite 数据库,然后使用 PyBind11 将该程序与 python 一起使用。我安装了 PyBind11,构建到这里没有问题,但是当我构建代码时,它显示一个错误:
/usr/include/python3.10/object.h:227: error: expected unqualified-id before ‘;’ token
In file included from /usr/include/python3.10/Python.h:74,
from /usr/local/include/pybind11/detail/common.h:266,
from /usr/local/include/pybind11/attr.h:13,
from /usr/local/include/pybind11/detail/class.h:12,
from /usr/local/include/pybind11/pybind11.h:13,
from /media/raghav/Sector 16/core/database.cpp:21:
/usr/include/python3.10/object.h:227:23: error: expected unqualified-id before ‘;’ token
227 | PyType_Slot *slots; /* terminated by slot==0. */
| ^
否则,我的代码可以正常工作,但我被困在这个问题上。我正在使用以下内容:
- Ubuntu
- CMake 3.24.2
- Qt Creator 10
- Python 3.10.6
请帮助我。提前致谢
答案1
感谢您的支持。解决方案是在导入 Qt 模块之前导入 pybind11,然后使用#define PYBIND11_NO_KEYWORDS