I thought my Flutter Linux desktop builds were rock solid until one day they weren’t. I hit one of those “everything was working fine yesterday” moments that every developer knows and loves.
I tried to build my app and got smacked with this:
/usr/include/glib-2.0/glib/glib-typeof.h:43:10: fatal error: 'type_traits' file not found
And after a hopeful flutter clean && flutter pub ge
it got worse:
The C++ compiler "/usr/bin/clang++" is not able to compile a simple test program.
...
/usr/bin/ld: невозможно найти -lstdc++: Нет такого файла или каталога
clang++: error: linker command failed with exit code 1
Basically the compiler can’t find <type_traits>
(a standard C++ header), and the linker can’t find libstdc++
(the standard C++ library). My toolchain was broken. Clang was chosen as the compiler, but the libraries it needed weren’t installed—or weren’t where CMake expected them.
Minimal Reproduction
I always like to strip things down to the smallest example. Here’s how I reproduced it:
flutter create hello_linux
cd hello_linux
flutter config --enable-linux-desktop
flutter run -d linux
lib/main.dart
:
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hello Linux',
home: Scaffold(
appBar: AppBar(title: const Text('Hello Linux')),
body: const Center(child: Text('It builds on my machine… right?')),
),
);
}
}
If this fails for you too, the issue is with your host system toolchain, not your Flutter code.
What Going On
fatal error: 'type_traits' file not found
Your compiler can’t find <type_traits>
because the C++ headers aren’t installed for your compiler/runtime (libstdc++ or libc++).
/usr/bin/ld: cannot find -lstdc++
The linker can’t find libstdc++.so
because the dev/runtime package is missing or mismatched.
Flutter uses CMake + Ninja for Linux builds. If Clang is installed, CMake will happily use it. But if Clang’s standard library version doesn’t match what’s on your system, you get this mess.
How I Fix It
Path A Use GCC
sudo apt update
sudo apt install build-essential cmake ninja-build pkg-config libgtk-3-dev clang
export CC=gcc
export CXX=g++
flutter clean
flutter build linux
Use Clang with Correct Runtime
Clang + libstdc++
sudo apt update
sudo apt install clang g++ build-essential cmake ninja-build pkg-config libgtk-3-dev
Clang + libc++
sudo apt update
sudo apt install clang libc++-dev libc++abi-dev cmake ninja-build pkg-config libgtk-3-dev
export CC=clang
export CXX=clang++
export CXXFLAGS="--stdlib=libc++"
export LDFLAGS="--stdlib=libc++"
flutter clean
flutter build linux
Fix Mismatched Version
If your distro moved from libstdc++ 12 → 13:
sudo apt install g++-13 libstdc++-13-dev
Sanity Check
Before blaming Flutter, check your toolchain:
clang++ -v
which clang++
ls -l /usr/lib/x86_64-linux-gnu/libstdc++.so*
Compile a tiny C++ file:
cat > /tmp/test.cpp <<'CPP'
#include <type_traits>
#include <iostream>
int main() {
static_assert(std::is_integral<int>::value);
std::cout << "C++ toolchain OK\n";
}
CPP
clang++ /tmp/test.cpp -o /tmp/test && /tmp/test
If this fails, it’s definitely your system.
Practice Project to Test the Fix
Once I got my toolchain working, I made a tiny FFI bridge from Flutter to C++ to prove linking was fine.
pubspec.yaml
dependencies:
ffi: ^2.1.0
linux/adder.cpp
extern "C" int add_two(int a, int b) { return a + b; }
linux/CMakeLists.txt
add_library(adder SHARED adder.cpp)
set_target_properties(adder PROPERTIES OUTPUT_NAME "adder")
target_link_libraries(${BINARY_NAME} PRIVATE adder)
lib/adder.dart
import 'dart:ffi' as ffi;
import 'dart:io';
typedef _NativeAdd = ffi.Int32 Function(ffi.Int32, ffi.Int32);
typedef _DartAdd = int Function(int, int);
class Adder {
late final _DartAdd _add;
Adder() {
final lib = ffi.DynamicLibrary.open('libadder.so');
_add = lib.lookupFunction<_NativeAdd, _DartAdd>('add_two');
}
int add(int a, int b) => _add(a, b);
}
main.dart
import 'package:flutter/material.dart';
import 'adder.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
final sum = Adder().add(21, 21);
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('FFI Test')),
body: Center(child: Text('21 + 21 = $sum')),
),
);
}
}
If it prints 21 + 21 = 42, your build toolchain is healthy.
Final Thought
This bug taught me something important:
When a Flutter Linux build breaks, don’t just stare at Flutter. Look at your compiler toolchain first.
Package updates, distro upgrades, or even installing Clang for another project can flip your default compiler or break the link to your C++ runtime. Knowing how to check the compiler, verify the standard library, and explicitly set CC/CXX can save hours of debugging.