You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ARM架构编译TensorFlow v1.14.0 Wheel包遇-march参数错误

问题:ARM架构编译TensorFlow v1.14.0 Wheel包时出现-march=native错误

问题背景

因PyPI无对应ARM架构的TensorFlow v1.14.0包,尝试自行编译Wheel包,环境配置如下:

  • gcc 4.8.0
  • bazel 0.24.1
  • Python 3.7

执行编译命令:

bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

持续报错:error: unknown value 'native' for -march,重新编译gcc和bazel后问题仍未解决。

环境信息

[root@ip-10-2-56-74 akash]# gcc --version
gcc (GCC) 4.8.0
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@ip-10-2-56-74 akash]# g++ --version
g++ (GCC) 4.8.0
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@ip-10-2-56-74 akash]# bazel version
OpenJDK 64-Bit Server VM warning: You have loaded library /root/.cache/bazel/_bazel_root/install/d650ee1515c4f5e6a88d60caf1201a2b/_embedded_binaries/libunix.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
Build label: 0.24.1- (@non-git)
Build target: bazel-out/aarch64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Dec 18 19:18:24 2023 (1702927104)
Build timestamp: 1702927104
Build timestamp as int: 1702927104

编译错误日志

[root@ip-10-2-56-74 tensorflow]# bazel build --config=opt  //tensorflow/tools/pip_package:build_pip_package
WARNING: /root/akash/tensorflow/tf1.14/tensorflow/tensorflow/python/BUILD:3469:1: in py_library rule //tensorflow/python:standard_ops: target '//tensorflow/python:standard_ops' depends on deprecated target '//tensorflow/python/ops/distributions:distributions': TensorFlow Distributions has migrated to TensorFlow Probability (https://github.com/tensorflow/probability). Deprecated copies remaining in tf.distributions will not receive new features, and will be removed by early 2019. You should update all usage of `tf.distributions` to `tfp.distributions`.
WARNING: /root/akash/tensorflow/tf1.14/tensorflow/tensorflow/python/BUILD:102:1: in py_library rule //tensorflow/python:no_contrib: target '//tensorflow/python:no_contrib' depends on deprecated target '//tensorflow/python/ops/distributions:distributions': TensorFlow Distributions has migrated to TensorFlow Probability (https://github.com/tensorflow/probability). Deprecated copies remaining in tf.distributions will not receive new features, and will be removed by early 2019. You should update all usage of `tf.distributions` to `tfp.distributions`.
WARNING: /root/akash/tensorflow/tf1.14/tensorflow/tensorflow/contrib/metrics/BUILD:16:1: in py_library rule //tensorflow/contrib/metrics:metrics_py: target '//tensorflow/contrib/metrics:metrics_py' depends on deprecated target '//tensorflow/python/ops/distributions:distributions': TensorFlow Distributions has migrated to TensorFlow Probability (https://github.com/tensorflow/probability). Deprecated copies remaining in tf.distributions will not receive new features, and will be removed by early 2019. You should update all usage of `tf.distributions` to `tfp.distributions`.
WARNING: /root/akash/tensorflow/tf1.14/tensorflow/tensorflow/contrib/learn/BUILD:17:1: in py_library rule //tensorflow/contrib/learn:learn: target '//tensorflow/contrib/learn:learn' depends on deprecated target '//tensorflow/contrib/session_bundle:exporter': No longer supported. Switch to SavedModel immediately.
WARNING: /root/akash/tensorflow/tf1.14/tensorflow/tensorflow/contrib/learn/BUILD:17:1: in py_library rule //tensorflow/contrib/learn:learn: target '//tensorflow/contrib/learn:learn' depends on deprecated target '//tensorflow/contrib/session_bundle:gc': No longer supported. Switch to SavedModel immediately.
WARNING: /root/akash/tensorflow/tf1.14/tensorflow/tensorflow/contrib/bayesflow/BUILD:17:1: in py_library rule //tensorflow/contrib/bayesflow:bayesflow_py: target '//tensorflow/contrib/bayesflow:bayesflow_py' depends on deprecated target '//tensorflow/contrib/distributions:distributions_py': TensorFlow Distributions has migrated to TensorFlow Probability (https://github.com/tensorflow/probability). Deprecated copies remaining in tf.contrib.distributions are unmaintained, unsupported, and will be removed by late 2018. You should update all usage of `tf.contrib.distributions` to `tfp.distributions`.
WARNING: /root/akash/tensorflow/tf1.14/tensorflow/tensorflow/contrib/BUILD:12:1: in py_library rule //tensorflow/contrib:contrib_py: target '//tensorflow/contrib:contrib_py' depends on deprecated target '//tensorflow/contrib/distributions:distributions_py': TensorFlow Distributions has migrated to TensorFlow Probability (https://github.com/tensorflow/probability). Deprecated copies remaining in tf.contrib.distributions are unmaintained, unsupported, and will be removed by late 2018. You should update all usage of `tf.contrib.distributions` to `tfp.distributions`.
INFO: Analysed target //tensorflow/tools/pip_package:build_pip_package (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /root/.cache/bazel/_bazel_root/f7ffa42ad2d77e736b0bd7227c78ca1d/external/protobuf_archive/BUILD:277:1: C++ compilation of rule '@protobuf_archive//:protoc_lib' failed (Exit 1)
external/protobuf_archive/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc:1:0: error: unknown value 'native' for -march
 // Protocol Buffers - Google's data interchange format
 ^
external/protobuf_archive/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc:1:0: warning: -fstack-protector not supported for this target [enabled by default]
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.487s, Critical Path: 0.05s
INFO: 2 processes: 2 local.
FAILED: Build did NOT complete successfully

解决方案

问题原因

gcc 4.8.0的ARM版本不支持-march=native参数,该参数在gcc 6及以上版本才对ARM架构生效,用于自动检测当前CPU的指令集并优化编译。

具体解决方法

  • 方法1:手动指定ARM架构编译参数
    在bazel编译命令中添加--copt参数,替换默认的-march=native为对应ARM架构的具体指令集,比如AArch64架构使用armv8-a:

    bazel build --config=opt --copt="-march=armv8-a" //tensorflow/tools/pip_package:build_pip_package
    

    若为32位ARM架构,可根据实际CPU型号选择armv7-a等参数。

  • 方法2:修改TensorFlow编译配置文件
    找到TensorFlow源码中的.bazelrc文件,或者在执行./configure脚本时,跳过自动优化选项,手动指定编译参数,将所有出现-march=native的配置替换为具体的ARM架构参数。

  • 方法3:升级gcc版本
    升级gcc到6.x及以上版本,新版本gcc支持在ARM架构上使用-march=native自动检测指令集,避免手动指定参数的麻烦。

内容的提问来源于stack exchange,提问作者Akash Kait

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 18:17:07