代码报错
-
zztg@zztg:~/mediapipe_test/build$ make
Consolidate compiler generated dependencies of target MediaPipeDetection
[ 50%] Building CXX object CMakeFiles/MediaPipeDetection.dir/src/main.cpp.o
In file included from /home/zztg/mediapipe/mediapipe/framework/calculator_state.h:27,
from /home/zztg/mediapipe/mediapipe/framework/calculator_context.h:25,
from /home/zztg/mediapipe/mediapipe/framework/calculator_base.h:26,
from /home/zztg/mediapipe/mediapipe/framework/calculator_framework.h:54,
from /home/zztg/mediapipe_test/src/main.cpp:3:
/home/zztg/mediapipe/mediapipe/framework/calculator.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
12 | #error This file was generated by a newer version of protoc which is
| ^~~~~
/home/zztg/mediapipe/mediapipe/framework/calculator.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
13 | #error incompatible with your Protocol Buffer headers. Please update
| ^~~~~
/home/zztg/mediapipe/mediapipe/framework/calculator.pb.h:14:2: error: #error your headers.
14 | #error your headers.
| ^~~~~
In file included from /home/zztg/mediapipe/mediapipe/framework/calculator.pb.h:36,
from /home/zztg/mediapipe/mediapipe/framework/calculator_state.h:27,
from /home/zztg/mediapipe/mediapipe/framework/calculator_context.h:25,
from /home/zztg/mediapipe/mediapipe/framework/calculator_base.h:26,
from /home/zztg/mediapipe/mediapipe/framework/calculator_framework.h:54,
from /home/zztg/mediapipe_test/src/main.cpp:3:
/home/zztg/mediapipe/mediapipe/framework/calculator_options.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
12 | #error This file was generated by a newer version of protoc which is
| ^~~~~
/home/zztg/mediapipe/mediapipe/framework/calculator_options.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
13 | #error incompatible with your Protocol Buffer headers. Please update
| ^~~~~
/home/zztg/mediapipe/mediapipe/framework/calculator_options.pb.h:14:2: error: #error your headers.
14 | #error your headers.
| ^~~~~
In file included from /usr/include/google/protobuf/map_entry_lite.h:37,
from /usr/include/google/protobuf/generated_message_table_driven.h:35,
from /home/zztg/mediapipe/mediapipe/framework/calculator.pb.h:26,
from /home/zztg/mediapipe/mediapipe/framework/calculator_state.h:27,
from /home/zztg/mediapipe/mediapipe/framework/calculator_context.h:25,
from /home/zztg/mediapipe/mediapipe/framework/calculator_base.h:26,
from /home/zztg/mediapipe/mediapipe/framework/calculator_framework.h:54,
from /home/zztg/mediapipe_test/src/main.cpp:3:
/usr/include/google/protobuf/stubs/casts.h: In function ‘To google::protobuf::internal::bit_cast(const From&)’:
/usr/include/google/protobuf/stubs/casts.h:120:25: error: ‘bit_cast_with_different_sizes’ was not declared in this scope
120 | bit_cast_with_different_sizes);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/google/protobuf/stubs/casts.h:119:3: error: there are no arguments to ‘GOOGLE_COMPILE_ASSERT’ that depend on a template parameter, so a declaration of ‘GOOGLE_COMPILE_ASSERT’ must be available [-fpermissive]
119 | GOOGLE_COMPILE_ASSERT(sizeof(From) == sizeof(To),
| ^~~~~~~~~~~~~~~~~~~~~ -
您遇到的错误提示表明有几个关键问题:
-
Protocol Buffers 版本不兼容:
- 错误信息指出,
calculator.pb.h
和calculator_options.pb.h
文件是由一个比您当前安装的 Protocol Buffers (protobuf) 库更新的版本的protoc
编译器生成的。这通常发生在当您使用的 protobuf 库版本低于用于生成这些.pb.h
文件的protoc
版本时。
- 错误信息指出,
-
缺少函数声明:
- 在
/usr/include/google/protobuf/stubs/casts.h
文件中,编译器找不到bit_cast_with_different_sizes
的声明,并且由于模板参数的问题,GOOGLE_COMPILE_ASSERT
宏也无法正确解析。这通常也是由于 protobuf 版本不匹配或安装不正确导致的。
- 在
解决步骤:
-
检查并更新 Protocol Buffers:
- 确定您系统上当前安装的 protobuf 版本。您可以使用
protoc --version
命令来查看。 - 检查 Mediapipe 项目文档或依赖项,看看它要求哪个版本的 protobuf。
- 如果需要,更新您的 protobuf 库。在 Ubuntu 上,您可以使用如下命令安装特定版本的 protobuf:
或者,您可能需要从源代码编译特定版本的 protobuf。sudo apt-get install protobuf-compiler=特定版本号 protobuf-c++-特定版本号
- 确定您系统上当前安装的 protobuf 版本。您可以使用
-
重新生成 protobuf 文件:
- 如果更新了 protobuf 版本,确保重新运行 Mediapipe 的 protobuf 生成步骤。这通常涉及到在 Mediapipe 的源代码目录中运行
protoc
命令。
- 如果更新了 protobuf 版本,确保重新运行 Mediapipe 的 protobuf 生成步骤。这通常涉及到在 Mediapipe 的源代码目录中运行
-
清理并重建项目:
- 在更新了 protobuf 并重新生成了必要的
.pb.h
文件后,清理您的构建目录(如果使用的是make
,可以运行make clean
),然后重新构建项目。
- 在更新了 protobuf 并重新生成了必要的
-
检查环境变量:
- 确保
protoc
的路径被正确设置在您的PATH
环境变量中,以便在构建过程中能够找到它。
- 确保
-
查看 Mediapipe 的文档和社区:
- 如果问题仍然存在,查看 Mediapipe 的官方文档或社区论坛,看看是否有其他人遇到了类似的问题以及他们是如何解决的。
通过这些步骤,您应该能够解决由于 protobuf 版本不兼容导致的问题,并成功构建您的 Mediapipe 项目。
以上为生成回答,仅供参考~
-
-
-
当你遇到与依赖项版本不兼容相关的错误时,确保所有库和框架的版本都匹配是非常重要的。对于你提到的 Mediapipe 项目和 protobuf(Protocol Buffers),你可以按照以下步骤来检测和调整依赖项的版本:
1. 检查 Mediapipe 的文档
首先,访问 Mediapipe 的官方文档或 GitHub 仓库。在文档或仓库的
README.md
文件中,通常会有关于依赖项版本的明确说明。特别是查找 protobuf 的版本要求。2. 使用
requirements.txt
或setup.py
如果 Mediapipe 项目提供了一个
requirements.txt
文件或者setup.py
脚本,这些文件会列出所有必要的依赖项及其版本。你可以查看这些文件来确定 protobuf 的确切版本。- requirements.txt:这个文件通常包含一行一个依赖项及其版本,如
protobuf==3.14.0
。 - setup.py:在
install_requires
部分也会列出依赖项。
3. 使用
pip list
或pip show
如果你已经安装了 Mediapipe 和 protobuf,可以使用以下命令来查看当前安装的版本:
pip list
这将列出所有已安装的 Python 包及其版本。你可以搜索
protobuf
来找到其版本。或者,使用:
pip show protobuf
这将显示关于 protobuf 的详细信息,包括版本。
4. 使用
pip freeze
另一个查看已安装依赖项版本的方法是使用
pip freeze
命令,它会生成一个已安装包的列表,格式与requirements.txt
兼容。5. 检查 Python 环境
如果你使用虚拟环境(如 venv 或 conda),确保你在正确的环境中操作。这可以避免版本冲突,因为每个环境都是独立的。
6. 更新或降级 protobuf
一旦你确定了 Mediapipe 所需的 protobuf 版本,你可能需要更新或降级 protobuf。使用以下命令:
pip install protobuf==特定版本
替换
特定版本
为 Mediapipe 所需的版本号。7. 清理和重新安装
有时候,完全卸载并重新安装依赖项可以解决版本冲突的问题。你可以使用以下命令来卸载并重新安装 protobuf:
pip uninstall protobuf pip install protobuf==特定版本
遵循这些步骤应该能帮助你解决与 Mediapipe 和 protobuf 版本相关的问题。如果问题仍然存在,可能需要检查 Mediapipe 的 GitHub 问题跟踪器或社区论坛,看看是否有其他人遇到并解决了相同的问题。
以上为生成回答,仅供参考~
- requirements.txt:这个文件通常包含一行一个依赖项及其版本,如