Help with errors when building OpenCV

I’m using the build script for apple found here:

I’m running the following command to build:
python3 /Users/xx/Downloads/opencv-4.7.0/platforms/apple/build_xcframework.py --out ./buildxc --macos_archs x86_64,arm64 --build_only_specified_archs

I see this error message:

#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer headers. Please regenerate this file with a newer version of protoc.

Protoc info:
protoc --version
libprotoc 3.21.12

I’ve tried reinstalling protoc but that hasn’t helped.

This link (opencv DNN build error · Issue #22674 · opencv/opencv · GitHub) suggests building with:

-DBUILD_PROTOBUF=OFF -DPROTOBUF_UPDATE_FILES=ON

But when I add that to the end of the command above I still see the error.

Any and all help appreciated! Thanks

Hi,

delete build folder and start again

Hi, I’ve tried that. I’ve also tried re-downloading the entire source again and starting again. I still see the issue.

Any other ideas?

Give your cmake command and cmake output

Command is: python3 /Users/xx/Downloads/opencv-4.7.0/platforms/apple/build_xcframework.py --out ./buildxc --macos_archs x86_64,arm64 --build_only_specified_archs

Are you only wanting to see errors from the output? I’ve put the full output in a text file (that I can’t attach), it’s 1.5MB!

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.

where is your cmakecache cmakeoutput files?

They are both in my build directory: …/buildxc/macOS/build/build-x86_64-macosx

Interestingly, I don’t have an build-arm64-macosx directory, it obviously didn’t get that far.

I get ‘unauthorised’ when I try to attached them here so here is a link to an archive with all three files (out, error, cache).

In cmakecahe.txt line 138

//Force to build libprotobuf runtime from sources
BUILD_PROTOBUF:BOOL=ON

and line 988

//Force rebuilding .proto files (protoc should be available)
PROTOBUF_UPDATE_FILES:BOOL=OFF

Something is wrong.
Do you want to use your own protobuf library? If yes you have to give path may be something as -DPROTOBUF_DIR=/usr… path to .cmake file

May be this and this can help you

1 Like

To be honest I don’t know what the protobuf library is. I’m just running the standard build script for Apple platforms included with opencv and I’m seeing the errors in the logs I’ve shared.

See here

The build command I’m running is:

python3 /Users/xx/Downloads/opencv-4.7.0/platforms/apple/build_xcframework.py --out ./buildxc --macos_archs x86_64,arm64 --build_only_specified_archs

I’ll trying building with cmake instead of using the python scripts.