Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link google protobuf libraries via cmake on linux?

Tags:

I'm trying to make it same way I made it for boost :

find_package(Boost COMPONENTS system filesystem REQUIRED)                                                     find_package(ProtocolBuffers)                                                                                  ## Compiler flags                                                                                             if(CMAKE_COMPILER_IS_GNUCXX)                                                                                      set(CMAKE_CXX_FLAGS "-O2")                                                                                    set(CMAKE_EXE_LINKER_FLAGS "-lsqlite3 -lrt -lpthread")                                                    endif()                                                                                                        target_link_libraries(complex                                                                                   ${Boost_FILESYSTEM_LIBRARY}                                                                                   ${Boost_SYSTEM_LIBRARY}                                                                                       ${PROTOBUF_LIBRARY}                                                                                         )   

(googled it somewhere) but got bad output:

CMake Warning at complex/CMakeLists.txt:18 (find_package):   Could not find module FindProtocolBuffers.cmake or a configuration file for   package ProtocolBuffers.    Adjust CMAKE_MODULE_PATH to find FindProtocolBuffers.cmake or set   ProtocolBuffers_DIR to the directory containing a CMake configuration file   for ProtocolBuffers.  The file will have one of the following names:      ProtocolBuffersConfig.cmake     protocolbuffers-config.cmake 

How can I link it with cmake? or maybe I even can compile .proto file using cmake?

like image 742
cnd Avatar asked Apr 04 '12 11:04

cnd


People also ask

What is protobuf in Linux?

Protocol Buffers (Protobuf) is a free and open-source cross-platform data format used to serialize structured data. It is useful in developing programs to communicate with each other over a network or for storing data.

What is Protobuf_generate_cpp?

The protobuf_generate_cpp function is responsible for executing the protoc and populating the PROTO_SRCS and PROTO_HDRS variables with their generated files. Without this functionality, you would need to manually add the protoc command and the required arguments.

How do I send protobuf over HTTP?

You can certainly send even a binary payload with an HTTP request, or in an HTTP response. Just write the bytes of the protocol buffer directly into the request/response, and make sure to set the content type to "application/octet-stream". The client, and server, should be able to take care of the rest easily.


1 Answers

You could try CMake's FindProtobuf module:

include(FindProtobuf) find_package(Protobuf REQUIRED) include_directories(${PROTOBUF_INCLUDE_DIR}) ... target_link_libraries(complex     ${Boost_FILESYSTEM_LIBRARY}     ${Boost_SYSTEM_LIBRARY}     ${PROTOBUF_LIBRARY} ) 


For further info, run

cmake --help-module FindProtobuf 
like image 144
Fraser Avatar answered Sep 25 '22 15:09

Fraser