man -k XPG4
reveals that there is a standards(5)
man page, which lists the feature test macros and library linking info for various standards, including the following:
X/Open CAE
To build or compile an application that conforms to one of
the X/Open CAE specifications, use the following guidelines.
Applications need not set the POSIX feature test macros if
they require both CAE and POSIX functionality.
SUS (XPG4v2)
The application must define _XOPEN_SOURCE with a value
other than 500 (preferably 1) and set
_XOPEN_SOURCE_EXTENDED=1.
Grepping through /usr/include
for _XOPEN_SOURCE
turns more information in /usr/include/sys/feature_tests.h
:
application writers wishing to use any functions specified as X/Open UNIX Extension must define _XOPEN_SOURCE
and _XOPEN_SOURCE_EXTENDED=1
. The Sun internal macro _XPG4_2
should not be used in its place as unexpected results may occur.
So defining _XPG4_2
yourself is not the way to do it.
If any structure definitions depend on these macros, you would definitely be better off defining them in all translation units. The easiest way to do that is to specify them on the compiler command line:
cc -D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1
If you're using make
, you should be able to do this by adding the -D
parameters to the CFLAGS
variable:
CFLAGS += -D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1