-D define not visible in C code with 9.10.1 on macOS via GHCUP
Summary
In the BSC project, we compile some C code with GHC and we have been using -D<name>
to define a macro that is consulted in the C code, and this has worked for a long time, installing many different versions of GHC via GHCUP on both Ubuntu and macOS OSes. We recently installed GHC 9.10.1 and found that the -D
is not visible in the C code, for macOS (versions 11, 12, 13, and 14) while the Ubuntu still works.
I am reporting this under the assumption that it's a bug with GHC. However, I see that the GHC user guide says that -D
does not influence the C compilation for unregisterised builds. So I guess it's possible that GHCUP has installed an unregisterised build (and GHC is behaving as expected). Is there a way to tell if the GHC installed on my system is an unregisterised build?
I can't find any information on what an "unregisterised build" is, to understand when you'd make such a build or how common it is. For one, if it does turn out that GHCUP has created one, would that be a bug to report to the GHCUP folks? Two, are they common enough that BSC's Makefiles should account for it, by specifying not only -D
flags but also -optc-D
?
Steps to reproduce
Create the file test.c
with the following contents:
int f(int x)
{
#ifdef FOO
return x;
#else
return y;
#endif
}
With GHC 9.10.1 installed via GHCUP on macOS (11/12/13/14), execute ghc -DFOO -c test.c
and it results in the following error message:
test.c:6:10: error:
error: use of undeclared identifier 'y'
return y;
^
|
6 | return y;
| ^
1 error generated.
`gcc' failed in phase `C Compiler'. (Exit code: 1)
If you execute with ghc -optc-DFOO -c test.c
, it compiles with no output. If you set GHCUP to use GHC of any other version, say 9.8.2, then both command-lines work (no error output).
Expected behavior
I expect both command-lines to work (no error) with GHC 9.10.1.
Environment
- GHC version used: 9.10.1
- Operating System: macOS 11 (on my laptop); macOS 11, 12, 13, and 14 (GitHub Action runner VMs)
- System Architecture: x86_64 for macOS 11, 12, and 13; arm64 (Apple M1) for macOS 14