如何在linux上通过cmake链接googleprotobuf库
How to link google protobuf libraries via cmake on linux?
我正试图以与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文件?
您可以尝试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
在这方面花了很多时间。。A.不同版本可能需要重新生成cc文件(显然)B.不同的版本有不同的命名(PROTOBUF_IBRARY与PROTOBUF_LIBRARIES)请注意,前面的答案指的是查看FindProtobuf帮助,其中说明了命名约定。此外,请使用"消息(STATUS"调试protobuf库位置:${protobuf_BRARIES}"以进行调试。
相关文章:
- Cmake 链接问题:未定义对 Button::mousePressEvent(QGraphicsSceneMouseE
- 将 SDL2 与 CMake 链接起来
- 找不到 CMake 链接的库
- 无法将 GTest 中的类与 CMake 链接
- NDK 将库与 cmake 链接
- 无法将提升库与 CMake 链接
- 如何使用 CMake 链接"numpy/arrayobject.h"
- CMake链接库在Docker映像中失败
- 使用cmake链接错误
- 如何使用CMake链接顶点?
- 无法在VS2017上将libclang与cmake链接
- 将枚举与 CMake 链接的正确方法是什么?
- 如何使用 cmake 链接库
- 将boost_numpy3与 CMAKE 链接
- CMake 链接 2 个具有相对路径的库
- Ogre 3D共享库与CMAKE链接时,在Linux上执行二进制时找不到
- 在 Android Studio 中使用 NDK、Gradle 和 CMake 链接外部库
- cmake链接错误2
- 无法通过 CMake 链接 Boost 1.63.0
- Android Native:CMake 链接错误:未定义对 GL 函数的引用 - 即使包含并链接了 EGL 和 GLESv3