我正在按照以下说明进行操作:
https://github.com/google/protobuf/tree/master/cmake
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=../../../../install/protobuf ../..
nmake install
在我程序的 CMakeLists.txt 中,我使用:
find_package(Protobuf REQUIRED)
但它告诉我:
-- Could NOT find Protobuf (missing: Protobuf_LIBRARIES Protobuf_INCLUDE_DIR)
我想我应该设置环境变量。
有没有有效的方法来做到这一点?
在 protobuf-master/cmake/install.cmake
中我可以看到这个:
configure_file(protobuf-config.cmake.in
${CMAKE_INSTALL_CMAKEDIR}/protobuf-config.cmake @ONLY)
configure_file(protobuf-config-version.cmake.in
${CMAKE_INSTALL_CMAKEDIR}/protobuf-config-version.cmake @ONLY)
configure_file(protobuf-module.cmake.in
${CMAKE_INSTALL_CMAKEDIR}/protobuf-module.cmake @ONLY)
configure_file(protobuf-options.cmake
${CMAKE_INSTALL_CMAKEDIR}/protobuf-options.cmake @ONLY)
这些文件可以设置环境变量吗?我该如何使用它们?
最佳答案
我更喜欢在项目的构建树中将第 3 方库构建为静态库。
我创建了一个 cmake 库来帮助解决这个问题。 protobuf 是我支持的首批库之一。文档很少,因此您可以随意提问或直接从文件 cmake/require_protobuf.cmake
图书馆在这里:https://github.com/madmongo1/sanity
如果你想做出贡献,我将不胜感激。
您将看到该脚本执行了 2 次构建。一个是在构建机器上构建 protoc
,另一个是为目标机器构建 protobuf 库。
关于c++ - 如何在 Windows 上使用 cmake 构建 google protobuf 环境?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38408486/