こども観察日記

子供達のおかしな生態の観察日記でした

gcc で #include <sys/signalfd.h> がコンパイルエラーした (Ubuntu 16.04)

  • gcc で #include コンパイルエラーする。というケースがある。
  • 自前のビルド環境で起きた。Makefileで色々構築している環境。
  • 結論としては -std=c11 を付けていたのが原因。なんじゃそりゃ。
    加えて Ubuntu 16.04 に標準で入る gcc というのが条件臭い。
  • signalfd.h の件は超嵌められたのでムカつくんだけど、実は本題はそれじゃない。
  • 以下のように -std の指定によって、__USE_POSIX が定義されたり、されなかったりする。(実行環境はUbuntu 18.04-2)
$ gcc --version
gcc (Ubuntu 7.4.0-1ubuntu1~18.04) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc -E -std=c90     -dM /usr/include/features.h | grep -w __USE_POSIX
$ gcc -E -std=gnu90   -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
$ gcc -E -std=c99     -dM /usr/include/features.h | grep -w __USE_POSIX
$ gcc -E -std=gnu99   -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
$ gcc -E -std=c11     -dM /usr/include/features.h | grep -w __USE_POSIX
$ gcc -E -std=gnu11   -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
$ g++ -E -std=c++98   -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
$ g++ -E -std=gnu++98 -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
$ g++ -E -std=c++03   -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
$ g++ -E -std=gnu++03 -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
$ g++ -E -std=c++11   -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
$ g++ -E -std=gnu++11 -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
$ g++ -E -std=c++14   -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
$ g++ -E -std=gnu++14 -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
$ g++ -E -std=c++1z   -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
$ g++ -E -std=gnu++1z -dM /usr/include/features.h | grep -w __USE_POSIX
#define __USE_POSIX 1
  • なんじゃこりゃ。っつーことですよ。
  • c11 に限らず、c90, c99 でも __USE_POSIX が定義されない。どうも意図的。
    代わりに gnu11 とかの GNU拡張有効にすると定義される。
    -std=c++XX は定義される。gnu++XX も同様に定義される。
  • ちょっと理由が分からないんです。誰か知りませんか?