c++ - 如何在 linux 上通过 cmake 链接 google protobuf 库?

标签 c++ cmake protocol-buffers

我正在尝试以与提升相同的方式制作它:

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

最佳答案

你可以试试 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

关于c++ - 如何在 linux 上通过 cmake 链接 google protobuf 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10010398/

相关文章:

CMake - 如何在目录名称中获取倒数第二个?

c++ - 如何将lua5.1添加到CMakeLists.txt?找不到错误 : lua. hpp

c++ - 通过Socket发送protocol buffer数据并判断类

c# - protobuf-net 与 C++ 通信

c++ - 不使用模板参数的模板类

c++ - Visual Studio C++ 2008/2010 - 浮点 NaN 中断

c++ - 实现 [B,C]=f(A) 语法(函数 f 作用于具有两个或多个输出数组的数组)

c++ - 我应该启动哪些 C++ 项目?

cmake - 从CMakeLists.txt文件设置CMAKE_INSTALL_PREFIX

python - 获取模块 'google.protobuf.descriptor_pool' 在我的 python 脚本中没有属性 'Default'