Fixing DuckDB Build From Source Issues on Ubuntu
Fixing DuckDB Build From Source Issues on Ubuntu
Building DuckDB from source on Ubuntu can sometimes throw you a curveball. Recently, I encountered a frustrating build error that took some digging to resolve. Here’s what happened and how to fix it.
The Problem
While trying to install DuckDB using uv add
on Ubuntu (with gcc 14.2.0), the build process was failing with a slew of warnings and errors. The most prominent issues were:
-
Writable strings warnings: Multiple
-Wwritable-strings
warnings throughout the codebase - Template argument errors: Fatal compilation errors related to missing template argument lists
Here’s a snippet of what the error output looked like:
1
2
3
4
5
6
7
8
9
10
11
duckdb_build/extension/tpcds/dsdgen/include/dsdgen_schema.hpp:342:32: warning: ISO C++11 does not allow conversion from string
literal to 'char *const' [-Wwritable-strings]
342 | static constexpr char *Name = "income_band";
| ^
duckdb_build/src/core_functions/aggregate/distributive/arg_min_max.cpp:167:20: error: a template argument list is expected after a
name prefixed by the template keyword [-Wmissing-template-arg-list-after-template-kw]
167 | STATE::template ReadValue(finalize_data.result, state.arg, target);
| ^
error: command '/usr/bin/clang++' failed with exit code 1
The Solution
The fix turned out to be surprisingly simple. The issue was with the compiler being used. By default, the system was using clang++
, which was being too strict about certain C++ constructs in the DuckDB codebase.
I encountered this bug while trying to install dlt-init-openapi
, which has DuckDB as a dependency. The same fix applies whether you’re installing DuckDB directly or as part of another package.
Quick Fix #1: Switch to g++
1
CXX=g++ uv add duckdb
By setting CXX=g++
, you’re instructing the build system to use the GNU C++ compiler instead of clang++. This resolved all the compilation errors immediately.
Alternative Fix #2: Suppress the Warnings
If you need to stick with clang++ for some reason, you can suppress the writable strings warnings:
1
CXXFLAGS="-Wno-writable-strings" uv add duckdb
Important Considerations
When building DuckDB from source, keep these limitations in mind:
-
C++23 Incompatibility: DuckDB’s codebase isn’t compatible with C++23. Don’t try to compile with
-std=c++23
as it will fail. -
Native Architecture Builds: The
-march=native
flag isn’t supported when building DuckDB.
Conclusion
Build errors can be frustrating, especially when they involve template metaprogramming and compiler-specific behaviors. In this case, the issue boiled down to compiler differences in how they handle certain C++ constructs. When in doubt, try switching compilers – it might just save you hours of debugging.