CMake在编译Google的protobuf示例时找不到protobuf

安德烈亚斯

我现在想解决这个问题已有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安装吗?

  • 似乎找到了这个“用作目录D:/protobuf-3.12.2/examples中的包含目录
  • 您是否正在尝试找到“ D:/ vcpkg / packages / protobuf_x64-windows”,不是吗?

尝试在Visual Studio的CMake选项中添加“ -DCMAKE_PREFIX_PATH =“ d:/ vcpkg / packages / protobuf_x64-windows”

祝您好运,如果不能解决问题,对不起,我是编程新手,但是值得一试。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在docker容器中安装CMake时出错。找不到PROTOBUF

Maven和Protobuf编译错误:在com.google.protobuf包中找不到符号

CMake找不到Protobuf`protobuf_generate_cpp`

找不到PROTOBUF编译器

错误:找不到模块“ google-protobuf”

Protobuf找不到共享库

grpc找不到protobuf libray

Python找不到protobuf文件

protobuf python找不到包含

vscode在编译时找不到标题,而Intellisense可以

Maven在编译时找不到sun.jvm.hotspot

在编译时找不到math.h:Hydra(Cygwin)

将protobuf编译为python,cmake命令

CMake目标依赖来编译protobuf文件

CMake:编译OpenCV时找不到CUDA库

编译器在编译时找不到重载的 operator<<。C++

Java在编译期间找不到符号

为什么 SBT 在编译时找到导入,而在构建项目时却找不到?

Dagger 2,有时在编译时出现“找不到符号类DaggerApplicationComponent”

扫描github.com/golang/protobuf/proto/testdata时出错:找不到包“”。

错误:协议失败:google / protobuf / wrappers.proto:找不到文件。(Maven构建中的错误)

com.sun.xml.internal.ws.developer.JAXWSProperties在编译时找不到

为什么在编译时使用扫描仪会出现“找不到符号”的问题?

Markdown在编织时找不到参数

在GOOGLE_PROTOBUF_MIN_PROTOC_VERSION检查期间编译时出现协议缓冲区错误

在Ubuntu 16.04中编译Ipopt示例时出现“找不到stddef.h”错误

找不到CMAKE交叉编译库

CMake找不到编译器

找不到io.confluent:kafka-protobuf-serializer:6.0.0