Posts Tagged ‘build’

The unintended consequences of using CFLAGS=-Werror with ./configure and gcc

March 5, 2024

Squid developers are striving (some may say “with varying levels of success”) to have a clean and safe codebase. One of the available tools is to rely on the compiler and instruct it to treat all warnings as errors to ensure all possibly meaningful signal on issues is caught and acted on. This is done with the -Wall -Werror compiler flags

However, we are not using these flags in ./configure – we set it in SQUID_CXXFLAGS which is a custom variable that’s later refrenced by Makefile.am and used during the build phase. Why is that?

The answer is: doing so would break key autoconf macros such as AC_CHECK_LIB, AC_SEARCH_LIBS, or AC_CHECK_FUNCS. These macros try to compile and link a test executable which calls a function (say, log defined in -lm ) with a standard signature: returning char and having no arguments.
Having -Werror turned on while using these functions will result in (tested with gcc 11.4):

configure:52533: gcc -o conftest -Wall -g -O2 -Werror -g conftest.c -lm >&5
conftest.c:366:6: error: conflicting types for built-in function 'log'; expected 'double(double)' [-Werror=builtin-declaration-mismatch]
366 | char log ();
| ^~~
conftest.c:1:1: note: 'log' is declared in header '<math.h>'
1 | /* confdefs.h */
cc1: all warnings being treated as errors

CFLAGS="-Werror -Wall -Wno-builtin-declaration-mismatch" ./configure will force ignoring this specific error and ensure that everything builds.

This is GCC specific; Clang doesn’t support this flag and will not exhibit the same behaviour

I could not find any mention of this in a quick internet search; hopefully this writeup will save someone else a bit of time and experimentation