首页 > 解决方案 > 规则“@com_google_protobuf//:protobuf”的 C++ 编译失败(退出 1)

问题描述

在未能在 macOS 上安装基于 Ubuntu 构建的 tensorflow 版本后,我决定只在 macbook 上构建,不到几分钟我就出现了 C++ 恐慌并且构建失败。

系统信息

错误:

ERROR: /private/var/tmp/_bazel_emadboctor/e4710f39cfc38993e5fe8f0eb15a51f2/external/com_google_p
rotobuf/BUILD:148:1: C++ compilation of rule '@com_google_protobuf//:protobuf' failed (Exit 1)
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:68:91: error: cannot initialize a member subobject of type 'int' with an lvalue of type 'void ()'
    {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_BoolValue_google_2fprotobuf_2fwrappers_2eproto}, {}};
                                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:82:91: error: cannot initialize a member subobject of type 'int' with an lvalue of type 'void ()'
    {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_BytesValue_google_2fprotobuf_2fwrappers_2eproto}, {}};
                                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:96:91: error: cannot initialize a member subobject of type 'int' with an lvalue of type 'void ()'
    {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_DoubleValue_google_2fprotobuf_2fwrappers_2eproto}, {}};
                                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:110:91: error: cannot initialize a member subobject of type 'int' with an lvalue of type 'void ()'
    {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_FloatValue_google_2fprotobuf_2fwrappers_2eproto}, {}};
                                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:124:91: error: cannot initialize a member subobject of type 'int' with an lvalue of type 'void ()'
    {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_Int32Value_google_2fprotobuf_2fwrappers_2eproto}, {}};
                                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:138:91: error: cannot initialize a member subobject of type 'int' with an lvalue of type 'void ()'
    {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_Int64Value_google_2fprotobuf_2fwrappers_2eproto}, {}};
                                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:152:91: error: cannot initialize a member subobject of type 'int' with an lvalue of type 'void ()'
    {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_StringValue_google_2fprotobuf_2fwrappers_2eproto}, {}};
                                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:166:91: error: cannot initialize a member subobject of type 'int' with an lvalue of type 'void ()'
    {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_UInt32Value_google_2fprotobuf_2fwrappers_2eproto}, {}};
                                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:180:91: error: cannot initialize a member subobject of type 'int' with an lvalue of type 'void ()'
    {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_UInt64Value_google_2fprotobuf_2fwrappers_2eproto}, {}};
                                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:310:20: error: no class named 'HasBitSetters' in 'google::protobuf::DoubleValue'
class DoubleValue::HasBitSetters {
      ~~~~~~~~~~~~~^
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:315:24: error: redefinition of 'kValueFieldNumber' as different kind of symbol
const int DoubleValue::kValueFieldNumber;
                       ^
/usr/local/include/google/protobuf/wrappers.pb.h:227:5: note: previous definition is here
    kValueFieldNumber = 1,
    ^
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:412:19: error: out-of-line definition of 'MergePartialFromCodedStream' does not match any declaration in 'google::protobuf::DoubleValue'
bool DoubleValue::MergePartialFromCodedStream(
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:456:19: error: out-of-line definition of 'SerializeWithCachedSizes' does not match any declaration in 'google::protobuf::DoubleValue'
void DoubleValue::SerializeWithCachedSizes(
                  ^~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:474:46: error: out-of-line definition of 'InternalSerializeWithCachedSizesToArray' does not match any declaration in 'google::protobuf::DoubleValue'
::PROTOBUF_NAMESPACE_ID::uint8* DoubleValue::InternalSerializeWithCachedSizesToArray(
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:561:19: error: redefinition of 'Swap'
void DoubleValue::Swap(DoubleValue* other) {
                  ^
/usr/local/include/google/protobuf/wrappers.pb.h:154:15: note: previous definition is here
  inline void Swap(DoubleValue* other) {
              ^
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:575:19: error: redefinition of 'UnsafeArenaSwap'
void DoubleValue::UnsafeArenaSwap(DoubleValue* other) {
                  ^
/usr/local/include/google/protobuf/wrappers.pb.h:162:8: note: previous definition is here
  void UnsafeArenaSwap(DoubleValue* other) {
       ^
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:595:19: error: no class named 'HasBitSetters' in 'google::protobuf::FloatValue'
class FloatValue::HasBitSetters {
      ~~~~~~~~~~~~^
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:600:23: error: redefinition of 'kValueFieldNumber' as different kind of symbol
const int FloatValue::kValueFieldNumber;
                      ^
/usr/local/include/google/protobuf/wrappers.pb.h:378:5: note: previous definition is here
    kValueFieldNumber = 1,
    ^
external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc:697:18: error: out-of-line definition of 'MergePartialFromCodedStream' does not match any declaration in 'google::protobuf::FloatValue'
bool FloatValue::MergePartialFromCodedStream(
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
Target //tensorflow/tools/pip_package:build_pip_package failed to build
ERROR: /Users/emadboctor/Desktop/tensorflow/tensorflow/core/framework/BUILD:1084:1 C++ compilation of rule '@com_google_protobuf//:protobuf' failed (Exit 1)
INFO: Elapsed time: 58.678s, Critical Path: 7.64s
INFO: 213 processes: 213 local.
FAILED: Build did NOT complete successfully
(tfb) emadboctor@MacBook-Pro tensorflow % 

重现:

conda create -n tfb
conda activate tfb
conda install pip six numpy wheel setuptools mock 'future>=0.17.1'
pip install -U keras_applications --no-deps
pip install -U keras_preprocessing --no-deps
git clone https://github.com/tensorflow/tensorflow.git
wget https://github.com/bazelbuild/bazel/releases/download/2.0.0/bazel-2.0.0-installer-darwin-x86_64.sh
chmod +x bazel-2.0.0-installer-linux-x86_64.sh
./bazel-2.0.0-installer-linux-x86_64.sh --user
export PATH=/home/emadboctor/bin:$PATH
cd tensorflow

配置:

./configure
You have bazel 2.0.0 installed.
Please specify the location of python. [Default is /Users/emadboctor/anaconda3/envs/tfb/bin/python]: 


Found possible Python library paths:
  /Users/emadboctor/anaconda3/envs/tfb/lib/python3.8/site-packages
Please input the desired Python library path to use.  Default is [/Users/emadboctor/anaconda3/envs/tfb/lib/python3.8/site-packages]

Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: 
No OpenCL SYCL support will be enabled for TensorFlow.

Do you wish to build TensorFlow with ROCm support? [y/N]: 
No ROCm support will be enabled for TensorFlow.

Do you wish to build TensorFlow with CUDA support? [y/N]: 
No CUDA support will be enabled for TensorFlow.

Do you wish to download a fresh release of clang? (Experimental) [y/N]: y
Clang will be downloaded and used to compile tensorflow.

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: 


Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: 
Not configuring the WORKSPACE for Android builds.

Do you wish to build TensorFlow with iOS support? [y/N]: y
iOS support will be enabled for TensorFlow.

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
    --config=mkl            # Build with MKL support.
    --config=monolithic     # Config for mostly static monolithic build.
    --config=ngraph         # Build with Intel nGraph support.
    --config=numa           # Build with NUMA support.
    --config=dynamic_kernels    # (Experimental) Build kernels into separate shared objects.
    --config=v2             # Build TensorFlow 2.x instead of 1.x.
Preconfigured Bazel build configs to DISABLE default on features:
    --config=noaws          # Disable AWS S3 filesystem support.
    --config=nogcp          # Disable GCP support.
    --config=nohdfs         # Disable HDFS support.
    --config=nonccl         # Disable NVIDIA NCCL support.
Configuration finished

构建命令:

bazel build -c opt --config=mkl --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-msse4.2 --copt=-msse4.1 --jobs 8 --verbose_failures //tensorflow/tools/pip_package:build_pip_package

标签: c++python-3.xmacosbuildtensorflow2.0

解决方案


推荐阅读