Repository: opencv
Issue: opencv-caffe.pb.h:17:2: error: This file was generated by an older version of protoc which is
Labels: duplicate,question (invalid tracker)

### System Information

```
OpenCV 4.6

OS: freebsd13
GCC version: (FreeBSD Ports Collection) 11.3.0
Clang version: 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
CMake version: version 3.24.0
Libc version: N/A

Python version: 3.9.13 (main, Aug 11 2022, 01:10:20)  [Clang 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c (64-bit runtime)
Python platform: FreeBSD-13.1-RELEASE-p1-amd64-64bit-ELF
Is CUDA available: N/A
CUDA runtime version: Could not collect
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A
```

### Detailed description

I get the following error when doing cmake:

```
[ 27%] Building CXX object modules/photo/CMakeFiles/opencv_photo.dir/src/align.cpp.o
[ 27%] Building CXX object modules/features2d/CMakeFiles/opencv_features2d.dir/src/affine_feature.cpp.o
[ 27%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/caffe/opencv-caffe.pb.cc.o
In file included from /home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.cc:4:
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:17:2: 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
 ^
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:18:2: error: incompatible with your Protocol Buffer headers. Please
#error incompatible with your Protocol Buffer headers. Please
 ^
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:19:2: error: regenerate this file with a newer version of protoc.
#error regenerate this file with a newer version of protoc.
 ^
In file included from /home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.cc:4:
In file included from /home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:26:
/home/user/opencv/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:299:25: error: no template named 'MapEntryHelper'
  bool operator()(const MapEntryHelper<T>& a,
                        ^
/home/user/opencv/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:300:25: error: no template named 'MapEntryHelper'
                  const MapEntryHelper<T>& b) const {
                        ^
/home/user/opencv/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:312:11: error: no template named 'MapEntryHelper'
  typedef MapEntryHelper<typename MapFieldType::EntryTypeTrait> Entry;
          ^
/home/user/opencv/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:325:38: error: member reference base type 'Entry' (aka 'int') is not a structure or union
      output->WriteVarint32(map_entry._cached_size_);
                            ~~~~~~~~~^~~~~~~~~~~~~~
/home/user/opencv/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:338:33: error: member reference base type 'std::__vector_base<int, std::allocator<int>>::value_type' (aka 'int') is not a structure or union
      output->WriteVarint32(v[i]._cached_size_);
                            ~~~~^~~~~~~~~~~~~~
In file included from /home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.cc:4:
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:20854:84: error: 'GetOwningArena' is a private member of 'google::protobuf::Arena::InternalHelper<opencv_caffe::BlobShape>'
        ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper<::opencv_caffe::BlobShape>::GetOwningArena(shape);
                                                                                   ^
/usr/local/include/google/protobuf/arena.h:415:19: note: declared private here
    static Arena* GetOwningArena(const T* p) { return p->GetOwningArena(); }
                  ^
In file included from /home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.cc:4:
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:21104:72: error: no member named 'EmptyDefault' in 'google::protobuf::internal::ArenaStringPtr'
 raw_data_.SetBytes(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:21117:68: error: no member named 'EmptyDefault' in 'google::protobuf::internal::ArenaStringPtr'
  raw_data_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:21121:79: error: no member named 'EmptyDefault' in 'google::protobuf::internal::ArenaStringPtr'
  return raw_data_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:21129:23: error: no member named 'ReleaseNonDefault' in 'google::protobuf::internal::ArenaStringPtr'
  auto* p = raw_data_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
            ~~~~~~~~~ ^
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:21144:7: error: too many arguments to function call, expected 2, have 3
      GetArenaForAllocation());
      ^~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/google/protobuf/arenastring.h:309:8: note: 'SetAllocated' declared here
  void SetAllocated(std::string* value, Arena* arena);
       ^
In file included from /home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.cc:4:
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:21469:90: error: 'GetOwningArena' is a private member of 'google::protobuf::Arena::InternalHelper<opencv_caffe::FillerParameter>'
        ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper<::opencv_caffe::FillerParameter>::GetOwningArena(scale_filler);
                                                                                         ^
/usr/local/include/google/protobuf/arena.h:415:19: note: declared private here
    static Arena* GetOwningArena(const T* p) { return p->GetOwningArena(); }
                  ^
In file included from /home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.cc:4:
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:22335:105: error: 'GetOwningArena' is a private member of 'google::protobuf::Arena::InternalHelper<opencv_caffe::NonMaximumSuppressionParameter>'
        ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper<::opencv_caffe::NonMaximumSuppressionParameter>::GetOwningArena(nms_param);
                                                                                                        ^
/usr/local/include/google/protobuf/arena.h:415:19: note: declared private here
    static Arena* GetOwningArena(const T* p) { return p->GetOwningArena(); }
                  ^
In file included from /home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.cc:4:
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:22425:94: error: 'GetOwningArena' is a private member of 'google::protobuf::Arena::InternalHelper<opencv_caffe::SaveOutputParameter>'
        ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper<::opencv_caffe::SaveOutputParameter>::GetOwningArena(save_output_param);
                                                                                             ^
/usr/local/include/google/protobuf/arena.h:415:19: note: declared private here
    static Arena* GetOwningArena(const T* p) { return p->GetOwningArena(); }
                  ^
In file included from /home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.cc:4:
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:22715:68: error: no member named 'EmptyDefault' in 'google::protobuf::internal::ArenaStringPtr'
 data_.SetBytes(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/home/user/opencv/modules/dnn/misc/caffe/opencv-caffe.pb.h:22728:64: error: no member named 'EmptyDefault' in 'google::protobuf::internal::ArenaStringPtr'
  data_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
[ 28%] Building CXX object modules/photo/CMakeFiles/opencv_photo.dir/src/calibrate.cpp.o
[ 28%] Building CXX object modules/features2d/CMakeFiles/opencv_features2d.dir/src/agast.cpp.o
[ 28%] Building CXX object modules/photo/CMakeFiles/opencv_photo.dir/src/contrast_preserve.cpp.o
[ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/onnx/opencv-onnx.pb.cc.o
20 errors generated.
--- modules/dnn/CMakeFiles/opencv_dnn.dir/misc/caffe/opencv-caffe.pb.cc.o ---
*** [modules/dnn/CMakeFiles/opencv_dnn.dir/misc/caffe/opencv-caffe.pb.cc.o] Error code 1

make[2]: stopped in /usr/home/user/opencv/build
--- modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all ---
*** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] Error code 6

make[1]: stopped in /usr/home/user/opencv/build
--- modules/photo/CMakeFiles/opencv_photo.dir/all ---
*** [modules/photo/CMakeFiles/opencv_photo.dir/all] Error code 6

make[1]: stopped in /usr/home/user/opencv/build
--- modules/features2d/CMakeFiles/opencv_features2d.dir/all ---
*** [modules/features2d/CMakeFiles/opencv_features2d.dir/all] Error code 6

make[1]: stopped in /usr/home/user/opencv/build
In file included from /home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.cc:4:
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:17:2: 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
 ^
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:18:2: error: incompatible with your Protocol Buffer headers. Please
#error incompatible with your Protocol Buffer headers. Please
 ^
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:19:2: error: regenerate this file with a newer version of protoc.
#error regenerate this file with a newer version of protoc.
 ^
In file included from /home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.cc:4:
In file included from /home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:26:
/home/user/opencv/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:299:25: error: no template named 'MapEntryHelper'
  bool operator()(const MapEntryHelper<T>& a,
                        ^
/home/user/opencv/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:300:25: error: no template named 'MapEntryHelper'
                  const MapEntryHelper<T>& b) const {
                        ^
/home/user/opencv/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:312:11: error: no template named 'MapEntryHelper'
  typedef MapEntryHelper<typename MapFieldType::EntryTypeTrait> Entry;
          ^
/home/user/opencv/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:325:38: error: member reference base type 'Entry' (aka 'int') is not a structure or union
      output->WriteVarint32(map_entry._cached_size_);
                            ~~~~~~~~~^~~~~~~~~~~~~~
/home/user/opencv/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:338:33: error: member reference base type 'std::__vector_base<int, std::allocator<int>>::value_type' (aka 'int') is not a structure or union
      output->WriteVarint32(v[i]._cached_size_);
                            ~~~~^~~~~~~~~~~~~~
In file included from /home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.cc:4:
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:3570:63: error: no member named 'EmptyDefault' in 'google::protobuf::internal::ArenaStringPtr'
 name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:3583:64: error: no member named 'EmptyDefault' in 'google::protobuf::internal::ArenaStringPtr'
  name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:3587:75: error: no member named 'EmptyDefault' in 'google::protobuf::internal::ArenaStringPtr'
  return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:3595:19: error: no member named 'ReleaseNonDefault' in 'google::protobuf::internal::ArenaStringPtr'
  auto* p = name_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
            ~~~~~ ^
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:3610:7: error: too many arguments to function call, expected 2, have 3
      GetArenaForAllocation());
      ^~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/google/protobuf/arenastring.h:309:8: note: 'SetAllocated' declared here
  void SetAllocated(std::string* value, Arena* arena);
       ^
In file included from /home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.cc:4:
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:3639:72: error: no member named 'EmptyDefault' in 'google::protobuf::internal::ArenaStringPtr'
 ref_attr_name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:3652:73: error: no member named 'EmptyDefault' in 'google::protobuf::internal::ArenaStringPtr'
  ref_attr_name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:3656:84: error: no member named 'EmptyDefault' in 'google::protobuf::internal::ArenaStringPtr'
  return ref_attr_name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:3664:28: error: no member named 'ReleaseNonDefault' in 'google::protobuf::internal::ArenaStringPtr'
  auto* p = ref_attr_name_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
            ~~~~~~~~~~~~~~ ^
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:3679:7: error: too many arguments to function call, expected 2, have 3
      GetArenaForAllocation());
      ^~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/google/protobuf/arenastring.h:309:8: note: 'SetAllocated' declared here
  void SetAllocated(std::string* value, Arena* arena);
       ^
In file included from /home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.cc:4:
/home/user/opencv/modules/dnn/misc/onnx/opencv-onnx.pb.h:3708:69: error: no member named 'EmptyDefault' in 'google::protobuf::internal::ArenaStringPtr'
 doc_string_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
--- modules/dnn/CMakeFiles/opencv_dnn.dir/misc/onnx/opencv-onnx.pb.cc.o ---
*** [modules/dnn/CMakeFiles/opencv_dnn.dir/misc/onnx/opencv-onnx.pb.cc.o] Error code 1

make[2]: stopped in /usr/home/user/opencv/build
2 errors

make[2]: stopped in /usr/home/user/opencv/build
--- modules/dnn/CMakeFiles/opencv_dnn.dir/all ---
*** [modules/dnn/CMakeFiles/opencv_dnn.dir/all] Error code 2

make[1]: stopped in /usr/home/user/opencv/build
4 errors

make[1]: stopped in /usr/home/user/opencv/build
*** [all] Error code 2

make: stopped in /usr/home/user/opencv/build
1 error

make: stopped in /usr/home/user/opencv/build
```

Thanks.

### Steps to reproduce

I simply done a cmake on FreeBSD 13.1

I need to have OpenGL support which FreeBSD OpenCV distro version seems not to have it.

### Issue submission checklist

- [X] I report the issue, it's not a question
- [X] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- [X] I updated to the latest OpenCV version and the issue is still there
- [X] There is reproducer code and related data files (videos, images, onnx, etc)