Help with errors when building OpenCV

Here’s some of the error output:

In file included from /Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.pb.cc:4:
/Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.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
 ^
/Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.pb.h:18:2: error: incompatible with your Protocol Buffer headers. Please
#error incompatible with your Protocol Buffer headers. Please
 ^
/Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.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 /Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.pb.cc:4:
In file included from /Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.pb.h:26:
/Users/xx/Downloads/opencv-4.7-2.0/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:299:25: error: no template named
      'MapEntryHelper'
  bool operator()(const MapEntryHelper<T>& a,
                        ^
/Users/xx/Downloads/opencv-4.7-2.0/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:300:25: error: no template named
      'MapEntryHelper'
                  const MapEntryHelper<T>& b) const {
                        ^
/Users/xx/Downloads/opencv-4.7-2.0/3rdparty/protobuf/src/google/protobuf/generated_message_table_driven.h:312:11: error: no template named
      'MapEntryHelper'
  typedef MapEntryHelper<typename MapFieldType::EntryTypeTrait> Entry;
          ^
/Users/xx/Downloads/opencv-4.7-2.0/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_);
                            ~~~~~~~~~^~~~~~~~~~~~~~
/Users/xx/Downloads/opencv-4.7-2.0/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_);
                            ~~~~^~~~~~~~~~~~~~
/Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.pb.cc:78:1: error: unknown type name 'PROTOBUF_ATTRIBUTE_INIT_PRIORITY'
PROTOBUF_ATTRIBUTE_INIT_PRIORITY static ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptorsRunner dynamic_init_dummy_versions_2eproto(&descriptor_table_versions_2eproto);
^
/Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.pb.cc:78:76: error: no member named 'AddDescriptorsRunner' in namespace
      'google::protobuf::internal'
PROTOBUF_ATTRIBUTE_INIT_PRIORITY static ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptorsRunner dynamic_init_dummy_versions_2eproto(&descriptor_table_versions_2eproto);
                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.pb.cc:78:96: error: expected ';' after top level declarator
PROTOBUF_ATTRIBUTE_INIT_PRIORITY static ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptorsRunner dynamic_init_dummy_versions_2eproto(&descriptor_table_versions_2eproto);
                                                                                               ^
                                                                                               ;
/Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.pb.cc:276:39: error: no member named 'CopyWithSizeCheck' in
      'google::protobuf::Message'; did you mean 'CopyWithSourceCheck'?
    ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
                                      CopyWithSourceCheck
In file included from /Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.pb.cc:4:
In file included from /Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.pb.h:30:
/opt/homebrew/include/google/protobuf/message.h:388:15: note: 'CopyWithSourceCheck' declared here
  static void CopyWithSourceCheck(Message& to, const Message& from);
              ^
/Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.pb.cc:277:5: error: cannot initialize a member subobject of type 'void
      (*)(google::protobuf::Message &, const google::protobuf::Message &)' with an lvalue of type 'void (::google::protobuf::Message *, const ::google::protobuf::Message &)': type
      mismatch at 1st parameter ('google::protobuf::Message &' vs '::google::protobuf::Message *')
    VersionDef::MergeImpl
    ^~~~~~~~~~~~~~~~~~~~~
13 errors generated.



note: Run script build phase 'Generate CMakeFiles/ALL_BUILD' will be run during every build because the option to run the script phase "Based on dependency analysis" is unchecked. (in target 'ALL_BUILD' from project 'OpenCV')
note: Run script build phase 'Generate CMakeFiles/ZERO_CHECK' will be run during every build because the option to run the script phase "Based on dependency analysis" is unchecked. (in target 'ZERO_CHECK' from project 'OpenCV')
note: Run script build phase 'Generate modules/objc_bindings_generator/CMakeFiles/gen_opencv_objc_source' will be run during every build because the option to run the script phase "Based on dependency analysis" is unchecked. (in target 'gen_opencv_objc_source' from project 'OpenCV')
** BUILD FAILED **


The following build commands failed:
	CompileC /Users/xx/Downloads/opencv-4.7-2.0/buildxc/macos/build/build-x86_64-macosx/build/opencv_world.build/Release/Objects-normal/x86_64/versions.pb.o /Users/xx/Downloads/opencv-4.7-2.0/modules/dnn/misc/tensorflow/versions.pb.cc normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'opencv_world' from project 'OpenCV')
(1 failure)
============================================================
ERROR: Command '['xcodebuild', 'MACOSX_DEPLOYMENT_TARGET=12.3', 'ARCHS=x86_64', '-sdk', 'macosx', '-configuration', 'Release', '-parallelizeTargets', '-jobs', '8', '-target', 'ALL_BUILD', 'build']' returned non-zero exit status 65.
============================================================
Traceback (most recent call last):
  File "/Users/xx/Downloads/opencv-4.7-2.0/platforms/ios/build_framework.py", line 181, in build
    self._build(outdir)
  File "/Users/xx/Downloads/opencv-4.7-2.0/platforms/ios/build_framework.py", line 139, in _build
    self.buildOne(target[0], target[1], main_build_dir, cmake_flags)
  File "/Users/xx/Downloads/opencv-4.7-2.0/platforms/ios/build_framework.py", line 318, in buildOne
    execute(buildcmd + ["-target", "ALL_BUILD", "build"], cwd = builddir)
  File "/Users/xx/Downloads/opencv-4.7-2.0/platforms/apple/cv_build_utils.py", line 13, in execute
    retcode = check_call(cmd, cwd = cwd)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['xcodebuild', 'MACOSX_DEPLOYMENT_TARGET=12.3', 'ARCHS=x86_64', '-sdk', 'macosx', '-configuration', 'Release', '-parallelizeTargets', '-jobs', '8', '-target', 'ALL_BUILD', 'build']' returned non-zero exit status 65.
============================================================
ERROR: Command '['python3', '/Users/xx/Downloads/opencv-4.7-2.0/platforms/osx/build_framework.py', './buildxc/macos', '--macos_archs', 'x86_64,arm64', '--framework_name', 'opencv2', '--build_only_specified_archs']' returned non-zero exit status 1.
============================================================
Traceback (most recent call last):
  File "/Users/xx/Downloads/opencv-4.7-2.0/platforms/apple/build_xcframework.py", line 99, in <module>
    execute(command, cwd=os.getcwd())
  File "/Users/xx/Downloads/opencv-4.7-2.0/platforms/apple/cv_build_utils.py", line 13, in execute
    retcode = check_call(cmd, cwd = cwd)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['python3', '/Users/xx/Downloads/opencv-4.7-2.0/platforms/osx/build_framework.py', './buildxc/macos', '--macos_archs', 'x86_64,arm64', '--framework_name', 'opencv2', '--build_only_specified_archs']' returned non-zero exit status 1.