- Protobufgenerate (LANGUAGE cpp TARGET PROTOS Foo.proto) This will directly add the generated files to the target's source list. Have a look in at the protobufgenerate function in protobuf-config.cmake for the new options.
- Protoc Installer¶. Protoc-installer is a Conan package focused in provide only protoc application and CMake files used to import macros, such as protobufgeneratecpp and protobufgenerate.It does not require any other package.
- GitHub Gist: instantly share code, notes, and snippets.
You call PROTOBUFGENERATEGRPCCPP but never use its results (files listed in ProtoGRPCSources and ProtoGRPCHeaders variables). Since the files are not used, CMake doesn't generate them. (Compare with PROTOBUFGENERATECPP call which creates files listed in PROTOSRC and PROTOHEADER variables. You use these files in addexecutable call, so they are generated before building the.
Hi folks,
how can I get
catkin
to build and deploy the results of protobuf's .proto
files? What's the SOTA in this regard? I've tried But that does nothing. It finds Protobuf but the bottom two commands basically do nothing. Not even throw an error.
Is this the recommended way?
Thank you!
![Protobuf_generate_cpp Protobuf_generate_cpp](https://inotgo.com/imagesLocal/202103/24/20210324173415384s_0.png)
Cheers,Hendrik
PS: I'm using
python-catkin-tools
, say, catkin build
instead of catkin_make
. In case that's some vital information..I managed to make it build by adding the line
to the
CMakeLists.txt
. This makes catkin
(or rather cmake
) build the Python bindings for my .proto
file. But it does not install it. Question extension 1
So I'll extend my question to: what do I need to add to the
CMakeLists.txt
in order for catkin
to copy the resulting ..pb2.py
file(s) to the correct folder (whichever that might be)?editretagflag offensiveclosemergedelete
Comments
This is not a Catkin question, but a CMake one.
How would you do this with pure CMake?
Probably exactly like in the example. But it still does not seem to work.. maybe it's CMake related. I thought there might be some catkin specific CMake commands for that.
I'm not aware of any protobuf specific infrastructure in Catkin.
I'd first get things working in a regular CMake context.
Then integrate that into a Catkin based
CMakeList.txt
.In my experience it should just work and there is nothing different between the two contexts (wrt protobuf at least).
I've extended the question to be a little more
catkin
specific.GraphQL Code Libraries, Tools and Services. Important
This tutorial will only work with eCAL 5.7.3 and upwards if you are using Windows.It will not work with older versions that were published as .msi installer (it missed some libraries).
Please switch to Ubuntu, if you are using an old eCAL Version.
In the last section you learned how to send strings to an eCAL Topic.Using strings is great for simple data that has a textual representation.Quite often however your data will be more complex, so you need some kind of protocol that defines how your data is structured.
Google Protobuf Example
Of course, you can define your own protocol and pass the raw memory to eCAL (you would use the raw eCAL::CPublisher() to do that).Our recommended way however is to use Google protobuf, because:
- It solves the problem of how to serialize and de-serialize data for you
- You get downward compatibility out of the box (if you follow the guidelines)
- It is maintained by Google and the API is stable
- The eCAL Monitor can display a nice reflection view of the data
Important
It is important to remember, that all your applications must agree on the data format.As protobuf messages are defined in
.proto
files, all of your applications should be compiled with the same files.7.2.1. Protobuf sender¶
Let’s implement a small application, that lets the user input his name and send a message to an eCAL topic.As the sender and receiver need the same .proto files, we place them in a separate directory next to the source directories for the sender and the receiver:
Let’s start with the
proto_messages/hello_world.proto
file!Note
What is happening here?
Line 3 assigns a package name (this will appear as C++ namespace later).
Line 5-10 Creates a message “HelloWorld”, that holds the fields “name”, “id” and “msg”.
Protobuf_generate_cpp Grpc
Now start implementing the actual sender application. Just as in the last section create the
CMakeLists.txt
and main.cpp
in the protobuf_snd
directory and paste the following content:CMakeLists.txt
:NoteWhat is happening here?Line 14 adds Protobuf as dependencyLine 20-22 Creates a list of .proto files. We only have one.Line 26 Compiles the .proto file to a C++ header file (hello_world.pb.h
).ThePROTOBUF_TARGET_CPP
function is a convenience function from eCAL.If you have already worked with Protobuf and CMake, you may be more familiar with the following code, which basically does the same thing:Line 30 links the executable against protobufmain.cpp
:Surfshark vpn price. NoteWhat is happening here?Line 2: This time, we include the protobuf publisher.Line7 includes the generated C++ file from thehello_world.proto
Line 13 creates a protobuf publisher instance.Note that it is templated toproto_messages::HelloWorld
, so if you would want to send different messages to different topics, you would create one publisher instance per topic.Sending different messages to the same topic is a bad idea and will break the de-serialization.Line 32-36 creates the message as protobuf object and sets the fields in it.Line 38 sends the protobuf object out to the topic.
Protobuf_generate_cpp Example
Again, you can already watch the sender doing its work by inspecting the topic in the eCAL Monitor!(Compile the application just as in the last section)
Important
The eCAL Monitor will not start listening to messages, until you open the reflection window.So, you will only see messages that were sent after you have opened the window.
7.2.2. Protobuf receiver¶
CMakeLists.txt
:main.cpp
:NoteWhat is happening here?Line 9 is our subscriber callback (you have already seen a callback in the last Hello World Tutorial).This time however it receives a protobuf object.Line 11-13 use the handy protobuf accessor methods to print the data to the terminal.Line 20 Creates an eCAL protobuf subscriber.Just like the publisher, it is templated to theproto_messages::HelloWorld
message.Line 23 Sets the callback, so eCAL can call it whenever a new message is received.
Now compile and start both the sender and the receiver application and send some messages!
Congratulations, you have completed the Getting Started chapter!Now go ahead and use eCAL in your real-world scenario.
If you experience issues, you can create a GitHub issue, to get help.