Chinaunix首页 | 论坛 | 博客
  • 博客访问: 148741
  • 博文数量: 54
  • 博客积分: 1732
  • 博客等级: 上尉
  • 技术积分: 520
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-23 23:29
文章分类

全部博文(54)

文章存档

2011年(3)

2010年(26)

2009年(25)

分类: LINUX

2009-11-07 19:20:29

前两天开始动手,想弄个gcc4.4玩玩,在网上google了一下,急匆匆的把源码给弄下来了,用的是svn:

svn checkout svn://gcc.gnu.org/svn/gcc/trunk gcc

首先找了个安装指南,地址在:
下面描述我的安装过程(系统:ubuntu9.04 x86_64,现有gcc版本:系统自带的4.3.3版本)

按照上面的指南的步骤,扫了一眼prerequistes,直接跳过(或许这是造成后面麻烦的原因之一吧)
然后开始配置,首先跳出gcc源码的顶层目录,建立gccobj目录,进入之后,第一次选择默认选项,所以,直接../gcc/configure
没跑两步就出问题了,看了下出错信息,恩,权限不够,于是乎改成sudo ../gcc/configure,还是不行,提示缺GMP, MPFR
马上sudo apt-get install GMP, MPFR, 无法找到安装包,换用小写依然一样,无奈之下google之,下载了其源码文件,按照里头的INSTALL文件提示安装完毕,源码文件可以在下面的地址下载:

重新configure,终于顺利配置完毕,生成makefile文件
然后make,继续权限错误,继续sudo……
事情的发展总是那么不尽如人意,没多久出现第一个错误:
gcc: gengtype-lex.c: No such file or directory
google之,找到答案,需要安装bison 与 flex
于是sudo apt-get install bison flex,再一次sudo make,依然出现同样的错误,抓狂了……
再一次google无果后,焦燥中扫了一眼出错信息,发现前面有一个warning,号称是没装flex,恩,莫非是需要重新configure?试试吧,重新弄了一次,同时增加了两个选项:
sudo ../gcc/configure --enable-bootstrap --enable-stage1-languagegs=c,c++
果然再一次sudo make时不再出现上面的错误,编译时间持续了一段时间,俺开始窃喜,恩,看来搞定了

事实无情的打击了我,编译工作再一次报错退出, 错误是:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
于是cat /usr/include/gnu/stubs.h,发现在定义了__x86_64__时,应该include的是stubs-64.h,我的系统里压根就没有stubs-32.h这个文件,当时就有冲动直接把stubs-64.h 文件名字改成32,编译完成后改回来,想一想,还是google一下吧,果然有更好的办法:

仔细的读完全篇,首先把CFLAGS设为-m64并且声明为环境变量,之后安装libc-dev-i386:
CFLAGS=-m64; export CFLAGS
sudo apt-get install libc-dev-i386
重新configure,问题解决,并且没有跟楼主一样使用--disable-multilib选项

但是挫折并没有结束,编译运行了近一个半小时后依然报错退出,
使用sudo make >make.log,屏幕显示错误信息如下:
WARNING: `makeinfo' is missing on your system.  You should only need it if
         you modified a `.texi' or `.texinfo' file, or any other file
         indirectly affecting the aspect of the manual.  The spurious
         call might also be the consequence of using a buggy `make' (AIX,
         DU, IRIX).  You might want to install the `Texinfo' package or
         the `GNU make' package.  Grab either from any GNU archive site.
make[7]: *** [cp-tools.info] 错误 1
make[6]: *** [all-recursive] 错误 1
Makefile:860: 警告:覆盖关于目标“gjdoc”的命令
Makefile:778: 警告:忽略关于目标“gjdoc”的旧命令
Makefile:860: 警告:覆盖关于目标“gjdoc”的命令
Makefile:778: 警告:忽略关于目标“gjdoc”的旧命令
make[5]: *** [all-recursive] 错误 1
make[4]: *** [all-recursive] 错误 1
make[3]: *** [multi-do] 错误 1
make[2]: *** [all-multi] 错误 2
make[1]: *** [all-target-libjava] 错误 2
make: *** [all] 错误 2

太困了,明天继续

继续google,按照网友提示,增加了一个环境变量:
export LC_ALL=C

同时将configure参数的改为:
sudo ../gcc/configure --enable-bootstrap --enable-languagegs=c,c++
继续make,上一个错误消除,但是继续产生新错误,崩溃ing
/stl_algobase.h:1152:32: fatal error: parallel/algobase.h: No such file or directory
compilation terminated.
make[4]: *** [parallel_list.lo] Error 1
make[4]: Leaving directory `/home/min/src/download/gccobj/x86_64-unknown-linux-gnu/libstdc++-v3/src'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/min/src/download/gccobj/x86_64-unknown-linux-gnu/libstdc++-v3'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/min/src/download/gccobj/x86_64-unknown-linux-gnu/libstdc++-v3'
make[1]: *** [all-target-libstdc++-v3] Error 2
make[1]: Leaving directory `/home/min/src/download/gccobj'
make: *** [all] Error 2

在系统内搜索了一下parallel/algobase.h,发现其是c++的头文件,位于/usr/include/c++/4.3.3/中,郁闷了,重新configure,添加--enable-build-with-cxx选项:
 sudo ../gcc/configure --enable-bootstrap --enable-languages=c,c++ --enable-build-with-cxx
还是出现错误:
Configuring stage 1 in ./intl
configure: loading cache ./config.cache
configure: error: `CFLAGS' has changed since the previous run:
configure:   former value:  `-g -fkeep-inline-functions'
configure:   current value: `-g'
configure: error: in `/home/min/src/download/gccobj/intl':
configure: error: changes in the environment can compromise the build
configure: error: run `make distclean' and/or `rm ./config.cache' and start over
make[2]: *** [configure-stage1-intl] Error 1
make[2]: Leaving directory `/home/min/src/download/gccobj'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/home/min/src/download/gccobj'
make: *** [all] Error 2
执行:make distclean,权限不够,使用sudo
依然错误,无奈,选择另一条路,先设定环境变量CPPFLAGS
export CPPFLAGS="-I /usr/include/c++/4.3.3"
重新configure并make

终于成功了~~~~
之后就简单了,按照安装说明
sudo make DESTDIR=/usr/local install
结果装在了/usr/local/usr/local中,郁闷的删除,重新sudo make install,好了
后来的事实证明,还不如就保持第一次安装的样子,第二次的安装使得以后如果想删除将很困难

运行 /usr/local/bin/g++ --version:
g++ (GCC) 4.5.0 20091103 (experimental)
Copyright (C) 2009 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.
似乎不是4.4版本,无所谓了,svn下载的嘛

写个hello world程序验证:
#include

int main(int argc, char* argv[])
{
    std::cout << "Hello World" << std::endl;
   
    return 0;
}
使用 /usr/local/bin/g++ hello.cc编译通过
但是运行的时候提示:
./a.out: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by ./a.out)
唉,不得不感叹前进的道路总是曲折的,之前的问题都解决了,这点小事自然不能让它成为绊脚石,google怎么添加链接库,找到答案:
sudo vi /etc/ld.so.conf
在其中添加以下三行:
/usr/local/lib32
/usr/local/lib64
/usr/local/libexec
然后运行
sudo /sbin/ldconfig
(具体参见:


竟然报错:
/sbin/ldconfig.real: /usr/local/lib32/libstdc++.so.6.0.14-gdb.py is not an ELF file - it has the wrong magic bytes at the start.

/sbin/ldconfig.real: /usr/local/lib64/libstdc++.so.6.0.14-gdb.py is not an ELF file - it has the wrong magic bytes at the start.
但是此时上面的a.out已经可以运行了

求助万能的google,倒是有人提供主意,但是没看懂:

如果哪位朋友能指点一二,万分感激:
xjtu.ym@gmail.com


阅读(5398) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-06-24 16:06:35

哥们儿,你这篇文章想说明啥?看完了,最后啥也没解决