Build failure with recent clang compiler when -stdlib flag is in CXXFLAGS
gpsd 3.25 fails to build on macOS with recent versions of clang (I'm using llvm.org clang 18 as installed by MacPorts):
gpsd-3.25/gpsd/ppsthread.c:162:12: error: incompatible integer to pointer conversion returning 'int' from a function with result type 'const char *' [-Wint-conversion]
return strerror_r(errnum, buf, len);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
This was reported to MacPorts here: https://trac.macports.org/ticket/69905
The reason is the that the configure test for strerror_r
gets the wrong result:
Checking if strerror_r() returns int... no
The reason is that the wrong flag has been passed to the compiler, which generates a warning, and you've requested that all warnings be turned into errors:
scons: Configure: Checking if strerror_r() returns int...
.sconf_temp/conftest_1d61eab1ffed995e90ff3652a575a466_0.c <-
|
| #define _GNU_SOURCE
|
| #include <stddef.h>
| #include <string.h>
|
| int main() {
| char buf[100];
| int ret;
|
| ret = strerror_r(24, buf, sizeof(buf));
| return ret;
| }
|
/opt/local/bin/clang-mp-18 -arch x86_64 -o .sconf_temp/conftest_1d61eab1ffed995e90ff3652a575a466_0_75cb1c7629a9486be0851ef046169149.o -c -Werror -Os -stdlib=libc++ -O2 .sconf_temp/conftest_1d61eab1ffed995e90ff3652a575a466_0.c
clang: error: argument unused during compilation: '-stdlib=libc++' [-Werror,-Wunused-command-line-argument]
scons: Configure: no
https://gitlab.com/gpsd/gpsd/-/blob/7d63237e19d500375b634dd034e3292bebb3066a/SConscript#L788-789
I am passing -stdlib=libc++
in CXXFLAGS, and your code use the SCons MergeFlags
function (which uses the ParseFlags
function) to move all of my flags from various environment variables to where SCons thinks they belong.
https://gitlab.com/gpsd/gpsd/-/blob/7d63237e19d500375b634dd034e3292bebb3066a/SConscript#L608-620
SCons does not know that -stdlib=libc++
belongs in CXXFLAGS so it puts it in CCFLAGS where it gets used for the C compiler which doesn't understand that option. That's a SCons bug which I will report to them but I'm also reporting it here because your users may encounter this error.
If turning warnings into an error is not required for this test, you could avoid the problem by not doing that.