Ubuntu 11.04以降で幾つかのアーキテクチャ依存ファイルのパスが変更されてしまい、upstream GCCを自前コンパイルするとインクルードやリンクが通らないという問題があります。
通常、/etc/environmentに
CPATH=/usr/include/x86_64-linux-gnu LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
などと書いておくと問題ないのですが、悲しいことにsudo経由等うまく環境変数を引き継げない場合にやはりエラーとなってしまいます。
ということでオープンソースなのでデフォルトで見るようにソースを書き換えましょう。
Ubuntu 12.04 amd64環境で、GCC 4.7.1 20120428(prerelease)時点でのdiffが以下のようになります。i686環境の人は追加部分のx86_64-linux-gnuをi386にすれば問題ないはずです。
--- gcc/collect2.c
+++ gcc/collect2.c
@@ -1363,6 +1363,7 @@
AIX loader always searches for libraries. */
add_prefix (&libpath_lib_dirs, "/lib");
add_prefix (&libpath_lib_dirs, "/usr/lib");
+ add_prefix (&libpath_lib_dirs, "/usr/lib/x86_64-linux-gnu");
#endif
/* Get any options that the upper GCC wants to pass to the sub-GCC.
--- gcc/gcc.c
+++ gcc/gcc.c
@@ -1100,6 +1100,9 @@
#ifndef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/"
#endif
+#ifndef STANDARD_STARTFILE_PREFIX_3
+#define STANDARD_STARTFILE_PREFIX_3 "/usr/lib/x86_64-linux-gnu/"
+#endif
#ifdef CROSS_DIRECTORY_STRUCTURE /* Don't use these prefixes for a cross compiler. */
#undef MD_EXEC_PREFIX
@@ -1139,6 +1142,8 @@
= STANDARD_STARTFILE_PREFIX_1;
static const char *const standard_startfile_prefix_2
= STANDARD_STARTFILE_PREFIX_2;
+static const char *const standard_startfile_prefix_3
+ = STANDARD_STARTFILE_PREFIX_3;
/* A relative path to be used in finding the location of tools
relative to the driver. */
@@ -6381,6 +6386,10 @@
add_sysrooted_prefix (&startfile_prefixes,
standard_startfile_prefix_2, "BINUTILS",
PREFIX_PRIORITY_LAST, 0, 1);
+ if (*standard_startfile_prefix_3)
+ add_sysrooted_prefix (&startfile_prefixes,
+ standard_startfile_prefix_3, "BINUTILS",
+ PREFIX_PRIORITY_LAST, 0, 1);
}
/* Process any user specified specs in the order given on the command
--- gcc/incpath.c
+++ gcc/incpath.c
@@ -459,7 +459,10 @@
/* Finally chain on the standard directories. */
if (stdinc)
- add_standard_paths (sysroot, iprefix, imultilib, cxx_stdinc);
+ {
+ add_standard_paths (sysroot, iprefix, imultilib, cxx_stdinc);
+ add_path ("/usr/include/x86_64-linux-gnu", SYSTEM, 1, false);
+ }
target_c_incpath.extra_includes (sysroot, iprefix, stdinc);
ハードコーディングバンザイ