How to link google protobuf libraries via cmake on linux?(如何在 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 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 linux 上通过 cmake 链接 google protobuf 库?
基础教程推荐
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01