我现在想解决这个问题已有2天,没有运气。我在网络上阅读了无数线程,并尝试了很多建议,但到目前为止还没有运气。
我在装有VS2017和最新VS Code的Windows 10上执行此操作。我安装了protobuf vcpkg install protobuf
:
软件包protobuf:x64-windows提供CMake目标:
find_package(protobuf CONFIG REQUIRED) target_link_libraries(main PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::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 Studio Code中编译项目时,无论我如何修改CMakeLists.txt文件,它始终会失败。如前所述,我经历了数十个有关此问题的线程,并尝试了很多运气。
更新29.05.2020
我检查了protobuf仅安装了一次,实际上演示包还包括完整的protobuf安装。我删除了这个额外的演示包,并使用vcpgk卸载/安装了protobuf。然后,我使用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.cmake
D:\vcpkg\installed\<BUILDCFG>\share\protobuf\protobuf-config.cmake
D:\vcpkg\packages\<BUILDCFG>\share\protobuf\protobuf-config.cmake
CMake无法找到这些文件的原因可能是什么?
一般警告,我不是专家。
我在自己的版本中遇到了类似的问题,试图使Boost正常工作,我认为这与您的环境变量以及您的Visual Studio设置有关。当您设置诸如
SET(PROTOBUF_INCLUDE_DIR "d:/vcpkg/packages/protobuf_x64-windows/include/")
实际的find_package(protobuf CONFIG REQUIRED)会将这些设置抛出窗口。一旦找到该配置文件,它只会在乎该配置文件在查找什么,我认为这是导致您的第一个MESSAGE拥有正确的配置文件,而第二个MESSAGE没有找到正确的配置文件的原因。
您确定您的计算机上只有一个protobuf安装吗?
尝试在Visual Studio的CMake选项中添加“ -DCMAKE_PREFIX_PATH =“ d:/ vcpkg / packages / protobuf_x64-windows”
祝您好运,如果不能解决问题,对不起,我是编程新手,但是值得一试。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句