我正试图解决这个问题2天,现在没有运气。我在网上阅读了无数的帖子,并尝试了很多建议,但到目前为止还没有什么好结果。
我是在Windows 10上用VS2017和最近安装的VS代码来做这件事。我用vcpkg install protobuf安装了原型
包protobuf:x64-windows提供了CMake目标: Find_package(原生质配置所需)target_link_libraries(主要私有原生质体::libprotobuf原生质体::libprotobuf原生质体::libprotobuf lite)
我下载了Google的示例代码并在我的驱动器上提取它。.PROTO文件编译时没有问题:
d:\protobuf-3.12.2\examples>protoc -I=d:\protobuf-3.12.2\examples --cpp_out=d:\protobuf-3.12.2\examples d:\protobuf-3.12.2\examples\addressbook.proto并按预期创建两个文件"addressbook.pb.cc“和"addressbook.pb.h”。
现在,当我试图在Visual代码中编译该项目时,无论我如何修改CMakeLists.txt文件,它都会经常失败。如前所述,我经历了几十个关于这个问题的线程,并在没有运气的情况下尝试了很多次。
更新29.05.2020
我检查了protobuf只安装了一次,实际上演示包还包括一个完整的protobuf安装。我删除了这个额外的演示包和使用vcpgk安装的un-/installed。然后,我使用protoc (在我的路径中)编译了.proto文件,得到了两个文件"addressbook.pb.cc“和"addressbook.pb.h”。
然后,我再次尝试编译该项目,这次使用演示附带的CMakeLists.txt。
有关的部分在开始时似乎是正确的:
# Minimum CMake required
cmake_minimum_required(VERSION 2.8.12)
# Project
project(protobuf-examples)
# Find required protobuf package
find_package(protobuf CONFIG REQUIRED)
if(protobuf_VERBOSE)
message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}")
endif()
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)汇编这篇文章给我的是:
[main] Building folder: examples
[main] Configuring folder: examples
[cms-client] Configuring using the "Visual Studio 15 2017" CMake generator with platform "x64" and toolset "host=x64"
[cmake] Selecting Windows SDK version 10.0.17763.0 to target Windows
...
[cmake] CMake Error at CMakeLists.txt:8 (find_package):
[cmake] Could not find a package configuration file provided by "protobuf" with any
[cmake] of the following names:
[cmake]
[cmake] protobufConfig.cmake
[cmake] protobuf-config.cmake
[cmake]
[cmake] Add the installation prefix of "protobuf" to CMAKE_PREFIX_PATH or set
[cmake] "protobuf_DIR" to a directory containing one of the above files. If
[cmake] "protobuf" provides a separate development package or SDK, be sure it has
[cmake] been installed.
[cmake]
[cmake]
[cmake] Configuring incomplete, errors occurred!
[cmake] See also "d:/vcpkg/buildtrees/protobuf/src/v3.12.0-8ba83cbbdb/examples/build/CMakeFiles/CMakeOutput.log".
[cms-driver] Error during CMake configure: [cmake-server] Configuration failed.可以在protobuf文件夹中多次找到protobuf-config.cmake文件:
D:\vcpkg\buildtrees\protobuf\<BUILDCFG>\share\protobuf\protobuf-config.cmakeD:\vcpkg\installed\<BUILDCFG>\share\protobuf\protobuf-config.cmakeD:\vcpkg\packages\<BUILDCFG>\share\protobuf\protobuf-config.cmakeCMake无法定位这些文件的原因是什么?
发布于 2020-05-28 17:23:55
公平的警告我不是专家。
我在自己的构建中遇到了一个类似的问题,我想这与您的环境变量以及Visual设置方式有关。当您设置关键的事情时,例如
SET(PROTOBUF_INCLUDE_DIR "d:/vcpkg/packages/protobuf_x64-windows/include/")实际的find_package(protobuf必需)将这些设置抛出窗口。一旦它找到了配置文件,它只关心配置文件找到了什么,我认为这就是为什么您的第一条消息是正确的,而第二条消息却找不到的原因。
你确定你在你的机器上只安装了一个原型吗?
尝试在Visual中将"-DCMAKE_PREFIX_PATH="d:/vcpkg/packages/protobuf_x64-windows"添加到CMake选项中
祝你好运,如果这没什么用的话,我对编程还是比较陌生的,但是值得一试。
发布于 2021-09-06 11:31:48
在这线程中,fraser解决了这个问题,但是如果您需要根据protobuf、CMake配置和CMake中的find_package命令进行开发,以查找protobuf库。您的protobuf库必须使用CMake编译,并且不使用配置例程。使用CMake编译protobuf之后,一个名为protobuf-config.cmake的配置文件将被生成到前缀/lib/CMake/protobuf目录中。
发布于 2020-05-28 17:31:18
如果问题是查找protobuf安装,那么您的protobuf路径不在环境变量中,请尝试将其添加到您的路径中,并让我知道如果它存在的话。会很乐意为你提供更多的帮助,以防这不起作用
https://stackoverflow.com/questions/62070189
复制相似问题