This file was generated by an older version of protoc

System information (version)
  • OpenCV => 4.3
  • Operating System / Platform => Windows 10 64 Bit
  • Compiler => Visual Studio 2017
Detailed description

Error:
This file was generated by an older version of protoc which is

I am trying to compile OpenCV from ~master, but having issues related with protobuf.
I tried various combination of those params but the issue remained persist:

  • BUILD_PROTOBUF + WITH_PROTOBUF
  • PROTOBUF_UPDATE_FILES + WITH_PROTOBUF (with this configuration, I also tried to point a manually built protobuf both 3.51 and 3.12.1)

Please note that without protobuf opencv does not compile the dnn module which I need it because I am maintaining an unofficial OpenCV binding for D programming language. The latest version that I was successfully building was 4.1. I was planning to update the repo to target version 4.3, but I stuck this issue. I see that some contrib modules such as SIFT were moved to the main repo.

I have a miniconda python installed that has also its own protoc.exe. Incase possible conflicts, I tried to rename it, but no effect.

math_functions.cpp
  ocl4dnn_conv_spatial.cpp
  ocl4dnn_inner_product.cpp
  ocl4dnn_lrn.cpp
  ocl4dnn_pool.cpp
  ocl4dnn_softmax.cpp
  onnx_graph_simplifier.cpp
D:\opencv4_dev\opencv\modules\dnn\misc\onnx\opencv-onnx.pb.h(17): fatal error C1189: #error:  This file was generated
by an older version of protoc which is (compiling source file D:\opencv4_dev\opencv\modules\dnn\src\onnx\onnx_graph_si
mplifier.cpp) [D:\opencv4_dev\Build\modules\world\opencv_world.vcxproj]
  onnx_importer.cpp
  op_halide.cpp
  op_inf_engine.cpp
  op_vkcom.cpp
D:\opencv4_dev\opencv\modules\dnn\misc\onnx\opencv-onnx.pb.h(17): fatal error C1189: #error:  This file was generated
by an older version of protoc which is (compiling source file D:\opencv4_dev\opencv\modules\dnn\src\onnx\onnx_importer

Steps to reproduce

CMakeCache.txt
CMakeVars.txt

Issue submission checklist
  • I report the issue, it’s not a question
  • I checked the problem with documentation, FAQ, open issues,
    answers.opencv.org, Stack Overflow, etc and have not found solution

  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

1 possible answer(s) on “This file was generated by an older version of protoc

  1. @alalek closed this. However, I think there is a problem with BUILD_PROTOBUF=ON. If it is set, cmake downloads protobuf ver 3.5.1 raising the problem. I could build the library by manually compiling protobuf ver 3.10.1.
    working configuration:
    WITH_PROTOBUFF=ON
    BUILD_PROTOBUF=OFF
    PROTOBUF_UPDATE_FILES=ON

    PROTOBUF_INCLUDE_DIR=D:/opencv4_dev/protobuf-3.10.1/src
    PROTOBUF_INCLUDE_DIRS=D:/opencv4_dev/protobuf-3.10.1/src
    PROTOBUF_LIBRARIES=D:/opencv4_dev/protobuf-3.10.1/build_win/Release/libprotobuf.lib
    PROTOBUF_LIBRARY=D:/opencv4_dev/protobuf-3.10.1/build_win/Release/libprotobuf.lib
    PROTOBUF_LITE_LIBRARIES=D:/opencv4_dev/protobuf-3.10.1/build_win/Release/libprotobuf-lite.lib
    PROTOBUF_LITE_LIBRARY=D:/opencv4_dev/protobuf-3.10.1/build_win/Release/libprotobuf-lite.lib
    PROTOBUF_PROTOC_EXECUTABLE=D:/opencv4_dev/protobuf-3.10.1/build_win/Release/protoc.exe
    PROTOBUF_PROTOC_LIBRARIES=D:/opencv4_dev/protobuf-3.10.1/build_win/Release/libprotoc.lib
    PROTOBUF_PROTOC_LIBRARY=D:/opencv4_dev/protobuf-3.10.1/build_win/Release/libprotoc.lib

    While manually compiling protobuf protobuf_MSVC_STATIC_RUNTIME must be off.