Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of __USE_XOPEN2K8 and how to set it?

Tags:

gcc

glibc

I'm trying to compile the gtk stack (the last gtk2 version, 2.24), and I am getting a bunch of errors that seem related. Namely, the __locale_t can't be found from string.h and time.h, and LC_ALL_MASK can't be found either (should be in locale.h).

I found that all of these problems are related to __USE_XOPEN2K8 not being #defined. What is __USE_XOPEN2K8 for, and how can I set it propertly?

For example, do I have to pass a flag to ./configure for glib, gtk, ... or do I have to change something already while building gcc or glib? I'd rather not just sprinkle #define __USE_XOPEN2K8 in to my sources without knowing what it does. Note I'm using gcc-4.6.3 and glibc-2.16.0 which are installed in a nonstandard prefix, as I'm trying to get the gtk libraries to work on an older CentOS (5.8) that only includes older versions.

Also note the missing __locale_t is mentioned in several places, e.g. this bugreport. I could just add #include <xlocale.h> in some files, but it seems the proper solution would be to get __USE_XOPEN2K8 to be set.


Edit: I've found this thread describing the problem. Apparently, headers of the host system get "fixincluded" into the headers of the new compiler. The linked post suggests to edit features.h. Does anyone know if I have to recompile gcc / glibc afterwards (and how to get it to pick up the new features.h, rather than overwriting it)?

like image 360
jdm Avatar asked Dec 14 '12 13:12

jdm


2 Answers

When __USE_GNU is defined, __USE_XOPEN2K8 is always defined as well, unless you are explicitly defining or undefining these macros, which you must not do. Use _GNU_SOURCE, _XOPEN_SOURCE {500,600,700,...} etc. macros before including the first header instead. This is the recommended way to select the GNU feature set in glibc headers, together with defining it on the command line (-D_GNU_SOURCE).

Alternatively, you can try specifying GNU extension usage to gcc through the -std command line switch (gnu89, gnu99, and so forth).

like image 162
Michael Foukarakis Avatar answered Sep 24 '22 03:09

Michael Foukarakis


On CentOS7 with gcc 4.6 we had to use -D_XOPEN_SOURCE=700 -D__USE_XOPEN2K8

like image 32
jluu Avatar answered Sep 21 '22 03:09

jluu