How to integrate this in a CMake project?
@Mizux ya está trabajando en esto.
Desde el 18/11/2026.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Área
- build-system
Línea de trabajo
Comienza con CMakeLists.txt y pybind11_protobuf/proto_cast_util.cc; después, inspecciona los archivos de desarrollo de Protobuf instalados para python/google/protobuf/proto_api.h y las rutas de inclusión configuradas. Verifica que el proyecto mínimo de CMake se compile y se ejecute sin errores de encabezado faltante ni errores del enlazador.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I am very interested in getting this to run in a CMake project and possibly contributing to make that happen.
I have this repo cloned as a submodule inside a small test project, but cannot get this to compile / run without linker errors.
This is my current setup:
Files
extern/pybind11_protobuf
CMakeLists.txt
fastproto.cpp
Person.proto
Person.proto:
syntax = "proto2";
message Person {
required int32 id = 2;
required string name = 1;
optional string email = 3;
}
fastproto.cpp
#include <pybind11/pybind11.h>
#include "Person.pb.h"
#include <string>
#include "pybind11_protobuf/native_proto_caster.h"
Person get_person() {
Person person;
person.set_id(1);
person.set_name(std::string{"Maximilian Nöthe"});
person.set_email(std::string{"[email protected]"});
return person;
}
PYBIND11_MODULE(fastproto, m) {
pybind11_protobuf::ImportNativeProtoCasters();
m.def("get_person", &get_person);
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.17..3.22)
project(Quirc++ VERSION 0.1.0 LANGUAGES C CXX)
include(GNUInstallDirs)
find_package(Python3 REQUIRED COMPONENTS Development Interpreter)
find_package(pybind11 REQUIRED)
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS Person.proto)
pybind11_add_module(
fastproto
fastproto.cpp
${PROTO_SRCS}
extern/pybind11_protobuf/pybind11_protobuf/native_proto_caster.cc
extern/pybind11_protobuf/pybind11_protobuf/proto_cast_util.cc
extern/pybind11_protobuf/pybind11_protobuf/proto_utils.cc
)
target_include_directories(fastproto PRIVATE ${CMAKE_CURRENT_BINARY_DIR} extern/pybind11_protobuf)
target_link_libraries(fastproto PRIVATE protobuf::libprotobuf)
target_compile_features(fastproto PRIVATE cxx_std_14)
set_target_properties(fastproto PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)
Or use the repo here: https://github.com/maxnoe/pybind_protobuf_test
Experimenting with this, I had several issues. However now in this version including the sources my main problem is that a protobuf header is not found:
❯ cmake --build build
-- Found pybind11: /usr/include (found version "2.9.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/maxnoe/Projects/protobuf_pybind/build
Consolidate compiler generated dependencies of target fastproto
[ 14%] Building CXX object CMakeFiles/fastproto.dir/extern/pybind11_protobuf/pybind11_protobuf/proto_cast_util.cc.o
/home/maxnoe/Projects/protobuf_pybind/extern/pybind11_protobuf/pybind11_protobuf/proto_cast_util.cc:19:10: fatal error: python/google/protobuf/proto_api.h: No such file or directory
19 | #include "python/google/protobuf/proto_api.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/fastproto.dir/build.make:126: CMakeFiles/fastproto.dir/extern/pybind11_protobuf/pybind11_protobuf/proto_cast_util.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/fastproto.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
It seems to be this one:
https://github.com/protocolbuffers/protobuf/blob/master/python/google/protobuf/proto_api.h
But that seems not to be part of an installed protobuf.
Any help on getting this to run would be appreciated.
- Lenguaje dominante
- C++
- Estrellas
- 67
- Forks
- 38
- Merge medio
- 14 h 48 min
- PR fusionados (30 d)
- 4
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pybind/pybind11_protobuf
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
pybind/pybind11_protobuf#104 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
pybind/pybind11_protobuf#232 · 2 comentarios ·
-
CMake USE_SYSTEM_... setup broken, wrong variable scopeQuizá libre de nuevo @Mizux la tomó hace 121 días y no hay ningún pull request abierto. Abiertobug dependencies
pybind/pybind11_protobuf#221 · 1 asignado ·
-
Build: Bazel help wanted
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
pybind/pybind11_protobuf#192 · 4 comentarios ·
-
Request: change std::optional to absl::optionalQuizá libre de nuevo @Mizux la tomó hace 712 días y no hay ningún pull request abierto. Abiertobug
pybind/pybind11_protobuf#184 · 3 comentarios · 2 reacciones · 1 asignado ·
Todos los issues de pybind/pybind11_protobuf
Issues similares
-
triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
patrick-hudson/put.gd-desktop#2044 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
uxlfoundation/oneDNN#6604 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
[Bug]: RoundToNearest truncates in plugins compiled with spcomp 1.13Posiblemente ocupada @fmu1337 la tomó hoy. AbiertoBug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
alliedmodders/sourcemod#2627 ·
Los mantenedores suelen responder en 1 día