Fatal error: php.h no such a file or directoryでコンパイルエラ

よくある話。

sourceからコンパイルしたい。
source.tar.gz解凍、./configure
make
生成される。どこかわからないときは、find ./ -name "*.so"とかで探そう。./.libsとかに吐かれること多し。


問題は、ヘッダがないよ、とコンパイルエラがでること。

今回はphp.hがないっつって、エラー出たので、その例で話す。

やることは、
エラー対象のヘッダがprefixで指定されるincludeにあるか?

なければ、それ探してインストールする。php.hの場合は、apt-get install php5-devする。

udo find / -name php.h
/usr/include/php5/main/php.h

これでも、makeしたら、エラーでる。
多分、prefixは何も指定してないので、/usr/include直下しかみてくれない。

解決策
まず、./configure --help=shortでオプション確認

./configure --help=short

Optional Features and Packages:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-libdir=NAME      Look for libraries in .../NAME rather than .../lib
  --with-php-config=PATH  Path to php-config php-config
  --enable-xdebug         Enable Xdebug support
  --enable-shared=PKGS  build shared libraries default=yes
  --enable-static=PKGS  build static libraries default=yes
  --enable-fast-install=PKGS  optimize for fast installation default=yes
  --with-gnu-ld           assume the C compiler uses GNU ld default=no
  --disable-libtool-lock  avoid locking (might break parallel builds)
  --with-pic              try to use only PIC/non-PIC objects default=use both
  --with-tags=TAGS      include additional configurations automatic


Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to the package provider.

手な感じで確認できる。

includeなので、CPPFLAGSあたりがつけそうだ。
ってことで.

CCPFLAG=-I/usr/include/php5/main/ ./configure --enable-xdebug

としてみた
んで、make

おおお^^^、できたできた。