如何在Linux上通过cmake链接Google protobuf库? [英] How to link google protobuf libraries via cmake on linux?

查看:329
本文介绍了如何在Linux上通过cmake链接Google protobuf库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以与增强相同的方式进行制作:

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

如何将其与cmake链接?也许我甚至可以使用cmake编译.proto文件?

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

推荐答案

您可以尝试CMake的 FindProtobuf 模块:

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

这篇关于如何在Linux上通过cmake链接Google protobuf库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆