Error: failed to run custom build command for `protobuf-src v1.1.0+21.5`

I am running into this error when I do cargo build:

error: failed to run custom build command for `protobuf-src v1.1.0+21.5`

Caused by:
  process didn't exit successfully: `/Users/dnyy/Desktop/Code/sugar-core-rs/target/debug/build/protobuf-src-d942991d3c0ad2ba/build-script-build` (exit status: 101)
  --- stdout
  running: cd "/Users/dnyy/Desktop/Code/sugar-core-rs/target/debug/build/protobuf-src-91babc4efa69e3f5/out/install/build" && CC="cc" CFLAGS="-O0 -ffunction-sections -fdata-sections -fPIC --target=arm64-apple-macosx15.2" CXX="c++" CXXFLAGS="-O0 -ffunction-sections -fdata-sections -fPIC --target=arm64-apple-macosx15.2" LC_ALL="C" "sh" "-c" "exec \"$0\" \"$@\"" "/Users/dnyy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/protobuf-src-1.1.0+21.5/protobuf/configure" "--prefix=/Users/dnyy/Desktop/Code/sugar-core-rs/target/debug/build/protobuf-src-91babc4efa69e3f5/out/install" "--disable-shared" "--enable-static" "--disable-maintainer-mode"

My protoc version is libprotoc 29.2

I have been stuck for a while and can't figure out what's wrong.

Is that the full error message? Isn't there a stack trace show right below of what you shared with us in your console? Note that protobuf-src tries to build libprotobuf and protoc from source. Might be that it fails building because you already have libprotoc installed on your system. Or you are missing system dependencies needed to build both artefacts. Which protobuf crate(s) are you using? You might have to change the feature set of your dependencies to avoid using a vendored libprotobuf in favour of the one from your system.

Which protobuf crate are you using?

I am using protobuf-src = "1.1.0".

Isn't there a stack trace show right below of what you shared with us in your console?

The trace shows

checking whether to enable maintainer-specific portions of Makefiles... no
  checking build system type... aarch64-apple-darwin23.5.0
  checking host system type... aarch64-apple-darwin23.5.0
  checking target system type... aarch64-apple-darwin23.5.0
  checking for a BSD-compatible install... /usr/bin/install -c
  checking whether build environment is sane... yes
  checking for a race-free mkdir -p... /Users/dnyy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/protobuf-src-1.1.0+21.5/protobuf/install-sh -c -d
  checking for gawk... no
  checking for mawk... no
  checking for nawk... no
  checking for awk... awk
  checking whether make sets $(MAKE)... yes
  checking whether make supports nested variables... yes
  checking whether UID '501' is supported by ustar format... yes
  checking whether GID '20' is supported by ustar format... yes
  checking how to create a ustar tar archive... gnutar
  checking whether make supports nested variables... (cached) yes
  checking for gcc... cc
  checking whether the C compiler works... yes
  checking for C compiler default output file name... a.out
  checking for suffix of executables... 
  checking whether we are cross compiling... no
  checking for suffix of object files... o
  checking whether the compiler supports GNU C... yes
  checking whether cc accepts -g... yes
  checking for cc option to enable C11 features... none needed
  checking whether cc understands -c and -o together... yes
  checking whether make supports the include directive... yes (GNU style)
  checking dependency style of cc... gcc3
  checking whether the compiler supports GNU C++... yes
  checking whether c++ accepts -g... yes
  checking for c++ option to enable C++11 features... none needed
  checking dependency style of c++... gcc3
  checking how to run the C preprocessor... cc -E
  checking for gcc... gcc
  checking whether the compiler supports GNU C... (cached) yes
  checking whether gcc accepts -g... yes
  checking for gcc option to enable C11 features... (cached) none needed
  checking whether gcc understands -c and -o together... (cached) yes
  checking dependency style of gcc... (cached) gcc3
  checking how to run the C preprocessor... gcc -E
  checking how to run the C++ preprocessor... c++ -E
  checking for g++... g++
  checking whether the compiler supports GNU C++... (cached) yes
  checking whether g++ accepts -g... yes
  checking for g++ option to enable C++11 features... (cached) none needed
  checking dependency style of g++... (cached) gcc3
  checking how to run the C++ preprocessor... g++ -E
  checking for stdio.h... yes
  checking for stdlib.h... yes
  checking for string.h... yes
  checking for inttypes.h... yes
  checking for stdint.h... yes
  checking for strings.h... yes
  checking for sys/stat.h... yes
  checking for sys/types.h... yes
  checking for unistd.h... yes
  checking for wchar.h... yes
  checking for minix/config.h... no
  checking whether it is safe to define __EXTENSIONS__... yes
  checking whether _XOPEN_SOURCE should be defined... no
  checking for ar... ar
  checking the archiver (ar) interface... ar
  checking for gcc... gcc
  checking whether the compiler supports GNU Objective C... yes
  checking whether gcc accepts -g... yes
  checking dependency style of gcc... gcc3
  checking C++ compiler flags...... use user-supplied: -O0 -ffunction-sections -fdata-sections -fPIC --target=arm64-apple-macosx15.2
  checking for c++ options needed to detect all undeclared functions... none needed
  checking whether __SUNPRO_CC is declared... no
  checking how to print strings... printf
  checking for a sed that does not truncate output... /usr/bin/sed
  checking for grep that handles long lines and -e... /usr/bin/grep
  checking for egrep... /usr/bin/grep -E
  checking for fgrep... /usr/bin/grep -F
  checking for ld used by cc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
  checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
  checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
  checking the name lister (/usr/bin/nm -B) interface... BSD nm
  checking whether ln -s works... yes
  checking the maximum length of command line arguments... 786432
  checking how to convert aarch64-apple-darwin23.5.0 file names to aarch64-apple-darwin23.5.0 format... func_convert_file_noop
  checking how to convert aarch64-apple-darwin23.5.0 file names to toolchain format... func_convert_file_noop
  checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r
  checking for file... file
  checking for objdump... objdump
  checking how to recognize dependent libraries... pass_all
  checking for dlltool... no
  checking how to associate runtime and link libraries... printf %s\n
  checking for archiver @FILE support... no
  checking for strip... strip
  checking for ranlib... ranlib
  checking command to parse /usr/bin/nm -B output from cc object... ok
  checking for sysroot... no
  checking for a working dd... /bin/dd
  checking how to truncate binary pipes... /bin/dd bs=4096 count=1
  checking for mt... no
  checking if : is a manifest tool... no
  checking for dsymutil... dsymutil
  checking for nmedit... nmedit
  checking for lipo... lipo
  checking for otool... otool
  checking for otool64... no
  checking for -single_module linker flag... ld: warning: -single_module is obsolete
  no
  checking for -exported_symbols_list linker flag... yes
  checking for -force_load linker flag... yes
  checking for dlfcn.h... yes
  checking for objdir... .libs
  checking if cc supports -fno-rtti -fno-exceptions... yes
  checking for cc option to produce PIC... -fno-common -DPIC
  checking if cc PIC flag -fno-common -DPIC works... yes
  checking if cc static flag -static works... no
  checking if cc supports -c -o file.o... yes
  checking if cc supports -c -o file.o... (cached) yes
  checking whether the cc linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
  checking dynamic linker characteristics... darwin23.5.0 dyld
  checking how to hardcode library paths into programs... immediate
  checking whether stripping libraries is possible... yes
  checking if libtool supports shared libraries... yes
  checking whether to build shared libraries... no
  checking whether to build static libraries... yes
  checking how to run the C++ preprocessor... c++ -E
  checking for ld used by c++... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
  checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
  checking whether the c++ linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
  checking for c++ option to produce PIC... -fno-common -DPIC
  checking if c++ PIC flag -fno-common -DPIC works... yes
  checking if c++ static flag -static works... no
  checking if c++ supports -c -o file.o... yes
  checking if c++ supports -c -o file.o... (cached) yes
  checking whether the c++ linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
  checking dynamic linker characteristics... darwin23.5.0 dyld
  checking how to hardcode library paths into programs... immediate
  checking whether the linker supports version scripts... no
  checking for egrep... (cached) /usr/bin/grep -E
  checking for fcntl.h... yes
  checking for inttypes.h... (cached) yes
  checking for limits.h... yes
  checking for stdlib.h... (cached) yes
  checking for unistd.h... (cached) yes
  checking for working memcmp... yes
  checking for working strtod... yes
  checking for ftruncate... yes
  checking for memset... yes
  checking for mkdir... yes
  checking for strchr... yes
  checking for strerror... yes
  checking for strtol... yes
  checking zlib version... ok (1.2.0.4 or later)
  checking for library containing zlibVersion... -lz
  checking whether c++ supports C++11 features by default... no
  checking whether c++ supports C++11 features with -std=c++11... no
  checking whether c++ supports C++11 features with +std=c++11... no
  checking whether c++ supports C++11 features with -h std=c++11... no
  checking whether c++ supports C++11 features with -std=c++0x... no
  checking whether c++ supports C++11 features with +std=c++0x... no
  checking whether c++ supports C++11 features with -h std=c++0x... no

  --- stderr
  configure: error: *** A compiler with support for C++11 language features is required.
  thread 'main' panicked at /Users/dnyy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/autotools-0.2.7/src/lib.rs:790:5:

  command did not execute successfully, got: exit status: 1

  build script failed, must exit now
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Could it be due to this A compiler with support for C++11 language features is required.? I'm on mac and my clang version is

Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

It seems the build script finds gcc and treats it as the default compiler.
What's the output of which cc and cc --version?
You might have an old gcc lying around, installed through homebrew or macports.

Also you might want to try protobuf-src = "2" which uses cmake for the build. The CMake output should include the C/C++ compiler and its version.

What do you need the protobuf-src dependency for, if you already have protoc and protobuf installed on your computer? Note the docs which state that:

This crate builds a vendored copy of libprotobuf and protoc using Cargo’s support for custom build scripts. It is not intended for direct consumption, but as a dependency for other crates that need libprotobuf or protoc available, like prost-build.

I managed to fix the issue after pointing my cpath to the right clang version. Thanks!

Trying to compile crate for solana, but getting the same error:

error: failed to run custom build command for `protobuf-src v1.1.0+21.5`

Caused by:
  process didn't exit successfully: `/Users/nsense/Desktop/.../target/debug/build/protobuf-src-4d5ad723e477eb27/build-script-build` (exit status: 101)

--- stderr
  configure: error: *** A compiler with support for C++11 language features is required.
  thread 'main' panicked at /Users/nsense/.cargo/registry/src/index.crates.io-6f17d22bba15001f/autotools-0.2.7/src/lib.rs:790:5:

  command did not execute successfully, got: exit status: 1

  build script failed, must exit now
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

gcc -v:

Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: arm64-apple-darwin24.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

MacOS Sequoia 15.2, Apple M1

What exactly did you do?

nvm, installed gcc@11 via brew

brew install gcc@11

then set to envs CC/CXX

export CC=/opt/homebrew/bin/gcc-11
export CXX=/opt/homebrew/bin/g++-11