proto/caffe.pb.h:17:2: error: #error This file was generated by an older version of protoc

本文针对《深度学习21天实战Caffe》一书中编译示例程序时遇到的错误进行了详细的分析,并提供了解决方案,包括清理旧的Protobuf安装、重新编译Protobuf等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

根据<<深度学习21天实战Caffe>>书中P102页,编写程序 blob_demo.cpp, 并把它放置在caffe目录下,
编译时出现如下提示:

sf@ubuntu:~/caffe$ g++ -o app ./blob_demo.cpp -I ./include/ -D CPU_ONLY -I ./.build_release/src -L . ild b/ -lcaffe
In file included from ./include/caffe/blob.hpp:9:0,
                 from ./blob_demo.cpp:3:
./.build_release/src/caffe/proto/caffe.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
 #error This file was generated by an older version of protoc which is
  ^
./.build_release/src/caffe/proto/caffe.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
 #error incompatible with your Protocol Buffer headers.  Please
  ^
./.build_release/src/caffe/proto/caffe.pb.h:19:2: error: #error regenerate this file with a newer version of protoc.
 #error regenerate this file with a newer version of protoc.
  ^
In file included from ./include/caffe/blob.hpp:9:0,
                 from ./bd.cpp:3:
./.build_release/src/caffe/proto/caffe.pb.h: In member function ‘void caffe::Datum::clear_data()’:
./.build_release/src/caffe/proto/caffe.pb.h:10766:17: error: ‘kEmptyString’ is not a member of ‘google::protobuf::internal’
   if (data_ != &::google::protobuf::internal::kEmptyString) {


                 ^
省略很多类似出错提示


 根据
/.build_release/src/caffe/proto/caffe.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
 #error This file was generated by an older version of protoc which is

是否 因为作者百度网盘上下的工具包 与现在从git上下载的caffe源程序不兼容?

后来查资料,参考如下:

Hi guys,
It seems this issue has been wrongly closed while some guys haven't managed to solve the problems with protobuf, protoc, .. So I would like to open this issue and give a thorough solution which would solve most of the problems regarding protobuf during caffe installation;
Here the solution goes:

Make sure you don't have already install protobuf and other similar name files
$ sudo apt-get clean
$ sudo apt-get autoclea
$ sudo apt-get autoremove
$ sudo apt-get remove --purge proto\tab              % remove all the files by pressing tab and finding those file or using *.   注:按tab键,补齐:protobuf-compiler
$ sudo dpkg -P proto\tab                                     注:不用按tab,可以直接写protobuf-compiler,  显示:没有此文件

After these steps you are sure that there is no already protobuf in your machine. you can do some of steps e.g. autoremove to make sure.

make sure you've tried installing:

这一步必须要执行:

sudo apt-get install libprotobuf-dev protobuf-compiler


then download protocol-buffer: https://developers.google.com/protocol-buffers/ for your OS.  可以从csdn上查找下载,google不通。
afterwards extract it in (Ubuntu)

$ tar zxvf protobuf-2.6.1.tar.gz
$ cd protobuf-2.6.1
$ ./configure                          这里改成参考书中的形式:   ./configure  --prefix=/home/sf/local_install/


把/home/sf/local_install/bin/protoc 文件删除,


$ make && make all.


生成新的 /home/sf/local_install/bin/protoc 


再对caffe进行

$ make

$ make test

$ make runtest

就可以把以上的错误解决了。

在执行./app之前,需要在命令提示符下 执行 :


$  export  LD_LIBRARY_PATH=/home/sf/caffe/build/lib:$LD_LIBRARY_PATH

$ ./app


以下是参考帖子中的内容,我的过程中没有出现。


if you during make all for caffe faced with error : error while loading shared libraries: libprotoc.so.9: cannot open shared object file: No such file or directory
fix it simly by sudo ldconfig.
if make all in caffe directory gives you error during make all, try this:
mkdir build && cd build
and then make all.
In this way, it's rare that you encounter with any error during the installation regarding protobuf.
Hopefully helps.

<think>好的,用户遇到了三个编译错误,需要逐一分析。首先看第一个错误:SSL_verify_cb类型未定义。这通常是因为OpenSSL的头文件没有正确包含或者版本不兼容。SSL_verify_cb是OpenSSL中的一个回调类型,可能在较新的版本中被引入或者重命名。需要检查用户的OpenSSL版本以及nats.c项目是否支持该版本。 第二个错误同样涉及SSL_verify_cb,说明问题可能在项目的头文件引用路径设置不正确,或者OpenSSL开发库未正确安装。用户可能安装了OpenSSL的运行时库,但缺少开发头文件,或者链接路径不正确。 第三个错误是protobuf-c版本不兼容的问题。用户使用的protoc-c生成的文件与系统中安装的libprotobuf-c版本不一致。这通常发生在用户手动编译安装了新版本的protoc-c,但系统中原有的库未更新,或者项目在编译时链接到了旧版本的头文件。 接下来,需要分步骤解决这些问题。首先处理SSL_verify_cb的问题,确保OpenSSL的开发包已正确安装,并且版本符合项目要求。然后处理protobuf-c的版本问题,可能需要更新libprotobuf-c或者重新生成协议文件。 考虑到用户之前的问题涉及protobuf头文件缺失,可能用户的环境存在多个版本冲突,或者在之前的安装中没有正确配置路径。需要检查protobuf和protobuf-c的安装情况,确保版本一致,并且编译时使用的protoc-c与库版本匹配。 最后,用户可能需要在编译时指定正确的包含路径和链接库路径,特别是如果自行编译了某些依赖项并安装在非标准位置。可能需要设置CFLAGS和LDFLAGS环境变量,或者在项目的配置脚本中传递正确的参数。</think>以下是针对 NATS.c 编译过程中出现的三类错误的系统性解决方案: --- ### **错误类型分解** | 错误序号 | 错误类型 | 关键信息 | |----------|--------------------------|----------------------------------------------| | 1-2 | OpenSSL 类型缺失 | `unknown type name ‘SSL_verify_cb’` | | 3 | protobuf-c 版本不兼容 | `generated by a newer version of protoc-c` | --- ### **第一阶段:解决 OpenSSL 类型缺失** #### **步骤1:验证 OpenSSL 开发环境** ```bash # 检查 openssl 开发包版本 openssl version -a | grep OpenSSL dpkg -l | grep -E 'libssl-dev|openssl' # 典型输出应包含: # ii libssl-dev:amd64 1.1.1f-1ubuntu2.20 amd64 Secure Sockets Layer toolkit - development files ``` #### **步骤2:版本兼容性处理** ```bash # 对于 OpenSSL 1.1.0+ 版本: # SSL_verify_cb 已更名为 SSL_verify_fn # 需要修改 NATS.c 源码中的类型声明 # 定位源码中的错误位置 grep -rn 'SSL_verify_cb' /home/liqi/liqi/software/nats.c/ # 修改示例 (具体行号根据实际输出调整): # 原代码:SSL_verify_cb callback; # 修改后:SSL_verify_fn callback; ``` #### **步骤3:强制指定 OpenSSL 版本** ```bash # 如果存在多版本共存,明确指定开发路径 export CFLAGS="-I/usr/include/openssl-1.1" export LDFLAGS="-L/usr/lib/openssl-1.1" # 重新配置编译 cd /home/liqi/liqi/software/nats.c/ make distclean ./configure make ``` --- ### **第二阶段:解决 protobuf-c 版本冲突** #### **步骤1:版本对齐策略** ```bash # 查看当前 protobuf-c 版本 protoc-c --version pkg-config --modversion protobuf-c # 输出示例: # protobuf-c 1.3.3 # 1.3.3 ``` #### **步骤2:源码升级方案** ```bash # 下载最新版 protobuf-c git clone https://github.com/protobuf-c/protobuf-c.git cd protobuf-c ./autogen.sh && ./configure && make sudo make install # 更新动态库缓存 sudo ldconfig ``` #### **步骤3:清理旧版本残留** ```bash # 删除可能存在的旧版本 sudo rm -f /usr/local/lib/libprotobuf-c.* sudo rm -rf /usr/local/include/google/protobuf-c/ ``` #### **步骤4:重新生成协议文件** ```bash # 进入 NATS.c 的协议文件目录 cd /home/liqi/liqi/software/nats.c/src/stan/ # 使用新 protoc-c 重新生成 protoc-c --c_out=. protocol.proto # 验证生成文件版本 head -n 5 protocol.pb-c.h | grep 'Generated by' ``` --- ### **第三阶段:综合编译验证** #### **编译参数修正** ```bash # 添加以下编译参数到 Makefile 或 configure 命令: CFLAGS="-I/usr/local/include -I/usr/include/openssl-1.1" LDFLAGS="-L/usr/local/lib -lprotobuf-c -lssl -lcrypto" ``` #### **完整编译流程** ```bash cd /home/liqi/liqi/software/nats.c/ make distclean ./configure \ --with-openssl=/usr \ --with-protobuf-c=/usr/local make -j$(nproc) sudo make install ``` --- ### **版本兼容矩阵** | 组件 | 最低要求版本 | 推荐版本 | |---------------|--------------|------------| | OpenSSL | 1.1.0 | 1.1.1t | | protobuf-c | 1.3.0 | 1.4.1 | | NATS.c | 2.9.0 | 3.3.0 | --- ### **典型案例处理** **场景:混合使用 APT 和源码安装导致冲突** ```bash # 完全清除旧版本 sudo apt purge libprotobuf-c-dev protobuf-c-compiler sudo rm -rf /usr/local/lib/libprotobuf-c* # 从源码安装指定版本 wget https://github.com/protobuf-c/protobuf-c/releases/download/v1.4.1/protobuf-c-1.4.1.tar.gz tar xzf protobuf-c-1.4.1.tar.gz cd protobuf-c-1.4.1 ./configure --prefix=/usr make sudo make install ``` --- ### **调试技巧** 1. **符号验证** ```bash nm -D /usr/local/lib/libprotobuf-c.so | grep protobuf_c_version # 应输出包含版本号的符号 ``` 2. **头文件包含顺序修正** ```c // 在出现错误的头文件包含前添加 #include <openssl/ssl.h> ``` --- 通过以上步骤可系统化解决编译错误问题,建议优先使用源码编译方式保持各组件版本一致性。若需长期维护,建议通过 Docker 容器化构建环境。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值