tensorflow
error
ISO C++ 2011
compiler support
library support

tensorflow error This file requires compiler and library support for the ISO C 2011 standard

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

The error This file requires compiler and library support for the ISO C++ 2011 standard occurs when building TensorFlow from source (or compiling a TensorFlow extension) with a C++ compiler that does not support C++11 or later. TensorFlow's codebase requires C++14 (and C++17 for newer versions), so an outdated compiler like GCC 4.x will fail with this message.

The Error

The full error message typically looks like:

 
error: #error This file requires compiler and library support for the
ISO C++ 2011 standard. This support must be enabled with the -std=c++11
or -std=gnu++11 compiler options.

Or on newer TensorFlow versions:

 
error: #error This file requires compiler and library support for the
ISO C++ 2014 standard.

Why This Happens

TensorFlow uses modern C++ features extensively:

  • C++11: auto, range-based for loops, std::shared_ptr, lambda expressions
  • C++14: Generic lambdas, std::make_unique, relaxed constexpr
  • C++17 (TF 2.12+): std::optional, structured bindings, if constexpr

The error occurs when:

  1. Your compiler is too old (GCC < 4.8 for C++11, GCC < 5 for C++14, GCC < 7 for C++17)
  2. The -std=c++11 (or higher) flag is not being passed to the compiler
  3. You are compiling a custom TensorFlow op or extension without the correct flags

How to Fix It

Fix 1: Upgrade Your Compiler

Check your current GCC version:

bash
gcc --version
g++ --version

Install a newer version:

bash
1# Ubuntu/Debian
2sudo apt update
3sudo apt install gcc-11 g++-11
4
5# Set as default
6sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 110
7sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 110
bash
1# CentOS/RHEL (using devtoolset)
2sudo yum install centos-release-scl
3sudo yum install devtoolset-11
4scl enable devtoolset-11 bash
5
6# Verify
7g++ --version  # Should show 11.x
bash
1# macOS
2brew install gcc
3# Use gcc-13 or later
4export CC=gcc-13
5export CXX=g++-13

Fix 2: Set the C++ Standard Flag

If your compiler supports C++14/17 but the flag is not being passed:

bash
1# When building TensorFlow from source with Bazel
2bazel build --cxxopt="-std=c++17" //tensorflow/...
3
4# When compiling a custom op
5g++ -std=c++17 -shared -fPIC my_op.cc -o my_op.so \
6    $(python -c 'import tensorflow as tf; print(tf.sysconfig.get_compile_flags()[0])') \
7    $(python -c 'import tensorflow as tf; print(tf.sysconfig.get_link_flags()[0])')

Fix 3: Use CMake with Proper Settings

If building with CMake:

cmake
1cmake_minimum_required(VERSION 3.14)
2project(my_tf_extension)
3
4set(CMAKE_CXX_STANDARD 17)
5set(CMAKE_CXX_STANDARD_REQUIRED ON)
6
7find_package(TensorFlow REQUIRED)
8add_library(my_op SHARED my_op.cc)
9target_link_libraries(my_op TensorFlow::TensorFlow)

Fix 4: Install Prebuilt TensorFlow Instead

If you are encountering this error while trying to install TensorFlow with pip, the fix is usually simpler — use the prebuilt wheel:

bash
1# This installs a prebuilt binary — no compilation needed
2pip install tensorflow
3
4# For GPU support
5pip install tensorflow[and-cuda]

The error only occurs when building from source or compiling custom ops.

TensorFlow Version Requirements

TensorFlow VersionMinimum C++ StandardMinimum GCCMinimum Clang
1.xC++114.83.3
2.0 - 2.9C++147.36.0
2.10 - 2.15C++179.311.0
2.16+C++1711.014.0

Building Custom TensorFlow Ops

When writing custom ops, use TensorFlow's build flags:

python
1import tensorflow as tf
2print(tf.sysconfig.get_compile_flags())
3# ['-I/path/to/tensorflow/include', '-D_GLIBCXX_USE_CXX11_ABI=1']
4
5print(tf.sysconfig.get_link_flags())
6# ['-L/path/to/tensorflow', '-l:libtensorflow_framework.so.2']

Compile with:

bash
1TF_CFLAGS=$(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))')
2TF_LFLAGS=$(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))')
3
4g++ -std=c++17 -shared -fPIC -o my_op.so my_op.cc $TF_CFLAGS $TF_LFLAGS -O2

Docker Alternative

If upgrading the system compiler is difficult, use a Docker container with the right toolchain:

dockerfile
1FROM tensorflow/tensorflow:latest-devel
2
3COPY my_op.cc /build/
4WORKDIR /build
5
6RUN g++ -std=c++17 -shared -fPIC -o my_op.so my_op.cc \
7    $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') \
8    $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))') -O2

Common Pitfalls

  • Multiple GCC versions: Having multiple GCC versions installed does not mean the right one is being used. Check which g++ and verify the version. Use update-alternatives to set the correct default.
  • CentOS/RHEL default GCC: CentOS 7 ships with GCC 4.8, which only supports C++11. Use devtoolset to get a newer version without replacing the system compiler.
  • Conda environments: Conda may install its own gcc that shadows the system version. Check conda list | grep gcc and ensure the conda compiler is new enough.
  • ABI compatibility: The -D_GLIBCXX_USE_CXX11_ABI flag must match between TensorFlow and your custom op. Get the correct value from tf.sysconfig.get_compile_flags().
  • macOS Xcode: On macOS, gcc is actually Clang (Apple's version). Use gcc --version to verify. Install real GCC from Homebrew if needed.

Summary

  • This error means your C++ compiler is too old or the -std=c++17 flag is not being passed
  • Upgrade GCC to version 9+ (or 11+ for TensorFlow 2.16+)
  • For custom ops, use tf.sysconfig.get_compile_flags() to get the correct build flags
  • Use pip install tensorflow for prebuilt binaries that do not require compilation
  • On CentOS/RHEL, use devtoolset to get a modern GCC without replacing the system compiler

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design