首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在linux上通过cmake链接google protobuf库?

如何在linux上通过cmake链接google protobuf库?
EN

Stack Overflow用户
提问于 2012-04-04 19:43:57
回答 1查看 29.7K关注 0票数 23

我试着让它像我为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}                                                                                        
)  

(在谷歌上搜索了一下),但得到的输出很差:

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文件?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-04 20:12:21

你可以试试CMake的FindProtobuf模块:

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

有关更多信息,请运行

cmake --help-module FindProtobuf
票数 41
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10010398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档