When defining macros that headers rely on, such as _FILE_OFFSET_BITS
, FUSE_USE_VERSION
, _GNU_SOURCE
among others, where is the best place to put them?
Some possibilities I've considered include
- At the top of the any source files that rely on definitions exposed by headers included in that file
- Immediately before the include for the relevant header(s)
- Define at the
CPPFLAGS
level via the compiler? (such as-D_FILE_OFFSET_BITS=64
) for the:- Entire source repo
- The whole project
- Just the sources that require it
- In project headers, which should also include those relevant headers to which the macros apply
- Some other place I haven't thought of, but is infinitely superior
A note: Justification by applicability to make, autotools, and other build systems is a factor in my decision.
I would always put them on the command line via
CPPFLAGS
for the whole project. If you put them any other place, there's a danger that you might forget to copy them into a new source file or include a system header before including the project header that defines them, and this could lead to extremely nasty bugs (like one file declaring a legacy 32-bitstruct stat
and passing its address to a function in another file which expects a 64-bitstruct stat
).BTW, it's really ridiculous that
_FILE_OFFSET_BITS=64
still isn't the default on glibc.Well, it depends.
Most, I'd define via the command line - in a Makefile or whatever build system you use.
As for
_FILE_OFFSET_BITS
I really wouldn't define it explicitly, but rather usegetconf LFS_CFLAGS
andgetconf LFS_LDFLAGS
.