LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1658|回复: 9

关于lfs过程中,找不到a.out文件的问题 和 mpfr 的问题

[复制链接]
发表于 2008-5-21 12:13:15 | 显示全部楼层 |阅读模式
原有系统
linux fc6
gcc version 4.1.1

lfs:
binutils-2.16.1
gcc-4.0.2

我完成 lfs 5.7章 调整工具链
测试
echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep ': $LFS/tools'
[Requesting program interpreter:  /tools/lib/ld-linux.so.2]
一切正常

然后在GCC-4.0.2 - 第二遍 时出现问题, 提示mpfr没有

运行
../gcc-4.0.2/configure --prefix=$LFS/tools \
--with-local-prefix=$LFS/tools --enable-clocale=gnu \
--enable-shared --enable-threads=posix \
--enable-__cxa_atexit --enable-languages=c,c++ \
--disable-libstdcxx-pch

提示
checking for correct version of gmp.h... yes
checking for MPFR... no
*** This configuration is not supported in the following subdirectories:
     target-libada target-libgfortran target-libffi target-boehm-gc target-zlib target-libjava zlib fastjar target-libobjc
    (Any other directories should still work fine.)

执行 make

checking for i686-pc-linux-gnu-gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details.
make: *** [configure-fixincludes] Error 1

查看sources/gcc-build/config.log,提示cannot find -lmpfr

configure:2284: checking for MPFR
configure:2297: gcc -o conftest -g -O2    conftest.c  -lmpfr -lgmp 1>&5
/mnt/lfs/tools/lib/gcc/i686-pc-linux-gnu/4.0.2/../../../../i686-pc-linux-gnu/bin/ld: cannot find -lmpfr
collect2: ld returned 1 exit status
configure: failed program was:
#line 2289 "configure"
#include "confdefs.h"
#include <gmp.h>
#include <mpfr.h>
int main() {
mpfr_t n; mpfr_init(n);
; return 0; }

查看sources/gcc-build/fixincludes/config.log,提示 a.out: No such file or directory

gcc (GCC) 4.0.2
Copyright (C) 2005 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.

configure:1746: $? = 0
configure:1748: gcc -v </dev/null >&5
Reading specs from /mnt/lfs/tools/lib/gcc/i686-pc-linux-gnu/4.0.2/specs
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.0.2/configure --prefix=/mnt/lfs/tools --with-local-prefix=/mnt/lfs/tools --disable-nls --enable-sha
red --enable-languages=c
Thread model: posix
gcc version 4.0.2
configure:1751: $? = 0
configure:1753: gcc -V </dev/null >&5
gcc: '-V' option must have argument
configure:1756: $? = 1
configure:1779: checking for C compiler default output file name
configure:1782: gcc -g -O2   conftest.c  >&5
configure:1785: $? = 0
configure:1831: result: a.out
configure:1836: checking whether the C compiler works
configure:1842: ./a.out
/mnt/lfs/sources/gcc-4.0.2/fixincludes/configure: line 1843: ./a.out: No such file or directory
configure:1845: $? = 127
configure:1854: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details.



这时发现一个问题

lfs:/mnt/lfs/sources$ echo 'main(){}' > dummy.c
lfs:/mnt/lfs/sources$ cc dummy.c
lfs:/mnt/lfs/sources$ readelf -l a.out | grep ': $LFS/tools'
      [Requesting program interpreter: $LFS/tools/lib/ld-linux.so.2]

lfs:/mnt/lfs/sources$ ./a.out
bash: ./a.out: No such file or directory
找不到a.out

可是ls 可以看到a.out文件
lfs:/mnt/lfs/sources$ ls -l
total 62180
-rwxr-xr-x  1 lfs  lfs      7652 May 21 11:53 a.out
-rw-r--r--  1 lfs  lfs         9 May 21 11:53 dummy.c
drwxr-xr-x 22 lfs  lfs      4096 May 21 11:45 gcc-4.0.2
-rwxr-Sr-t  1 root root    14802 May 20 16:01 gcc-4.0.2-specs-1.patch
-rwxr-Sr-t  1 root root 31793160 May 20 11:08 gcc-4.0.2.tar.bz2
drwxr-xr-x  3 lfs  lfs      4096 May 21 11:49 gcc-build
-rwxr-Sr-t  1 root root     2221 May 20 13:23 glibc-2.3.6-static-nss-fix-shy-1.patch
-rwxr-Sr-t  1 root root 14014977 May 20 13:22 glibc-2.3.6.tar.bz2
drwxr-xr-x 15 lfs  lfs      4096 Sep 11  2007 gmp-4.2.2
-rwxr-Sr-t  1 root root  1747068 May 20 18:12 gmp-4.2.2.tar.bz2
drwxr-xr-x  2 lfs  lfs      4096 May 20 18:17 gmp-build
-rwxr-Sr-t  1 root root  2539721 May 20 13:16 linux-libc-headers-2.6.12.0.tar.bz2

lfs:/mnt/lfs/sources$ which gcc
/mnt/lfs/tools/bin/gcc
lfs:/mnt/lfs/sources$ which cc
/mnt/lfs/tools/bin/cc
lfs:/mnt/lfs/sources$ which ld
/mnt/lfs/tools/bin/ld
lfs:/mnt/lfs/sources$ which ldd
/mnt/lfs/tools/bin/ldd


新开一个终端,root用户, 仍然不行
[root@zebecpc sources]# ./a.out
-bash: ./a.out: No such file or directory

[root@zebecpc sources]# ls -l
total 62180
-rwxr-xr-x  1 lfs  lfs      7652 May 21 11:53 a.out
-rw-r--r--  1 lfs  lfs         9 May 21 11:53 dummy.c
drwxr-xr-x 22 lfs  lfs      4096 May 21 11:45 gcc-4.0.2
-rwxr-Sr-t  1 root root    14802 May 20 16:01 gcc-4.0.2-specs-1.patch
-rwxr-Sr-t  1 root root 31793160 May 20 11:08 gcc-4.0.2.tar.bz2
drwxr-xr-x  3 lfs  lfs      4096 May 21 11:49 gcc-build
-rwxr-Sr-t  1 root root     2221 May 20 13:23 glibc-2.3.6-static-nss-fix-shy-1.patch
-rwxr-Sr-t  1 root root 14014977 May 20 13:22 glibc-2.3.6.tar.bz2
drwxr-xr-x 15 lfs  lfs      4096 Sep 11  2007 gmp-4.2.2
-rwxr-Sr-t  1 root root  1747068 May 20 18:12 gmp-4.2.2.tar.bz2
drwxr-xr-x  2 lfs  lfs      4096 May 20 18:17 gmp-build
-rwxr-Sr-t  1 root root  2539721 May 20 13:16 linux-libc-headers-2.6.12.0.tar.bz2

然后我用root用户执行
[root@zebecpc sources]# rm -rf dummy.c a.out
[root@zebecpc sources]# echo 'main(){}' > dummy.c
[root@zebecpc sources]# cc dummy.c
[root@zebecpc sources]# ./a.out
可以运行

切换回lfs用户,执行root用户编译的a.out文件
lfs:/mnt/lfs/sources$ ./a.out  
lfs:/mnt/lfs/sources$
没有问题


大家帮我看看,mpfr是否可以不用,怎么关掉它?
a.out找不到是什么原因? 感觉lfs用户编译的a.out有问题

这两个问题有关系吗?

谢谢
发表于 2008-5-21 18:47:37 | 显示全部楼层
lz 配置编译gcc时是否选中fortran,不然GCC-4.0.2不会提示mpfr,检查一下gcc配置参数是否正确。
回复 支持 反对

使用道具 举报

发表于 2008-5-21 18:50:41 | 显示全部楼层
1. mpfr在你的GCC版本下不是必选项。你可以忽略这个警告。
2. 你的第一遍gcc有问题,有可能是动态加载器出了问题。a,out是好的,但是它所用到的动态库找不到,因此会出现找不到文件的提示。请检查动态加载器以及libc.so.6是否在适当的路径上。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-5-22 10:59:06 | 显示全部楼层
to 1987a:
我的第一遍编译如下

tar xvf gcc-4.0.2.tar.bz2
mkdir gcc-build
cd gcc-build
../gcc-4.0.2/configure --prefix=$LFS/tools --with-local-prefix=$LFS/tools --disable-nls --enable-shared --enable-languages=c
make bootstrap
make install

这样会造成你说的问题吗?我指定了--enable-languages=c呀


to  地球发动机:
我的第一遍gcc编译如上, 当前在$LFS/tools/lib下有libc.so.6文件,
我不明白你说的动态加载器出了问题是什么意思?

echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep ': $LFS/tools'
[Requesting program interpreter: /tools/lib/ld-linux.so.2]

这个执行结果不能说明回答你说的问题吗?

你说:“mpfr在你的GCC版本下不是必选项。你可以忽略这个警告。”
我不能确定当前的编译的错误,是否可以忽略mpfr,还是a.out的问题。应为这是两个问题,等解决了a.out的问题再看看mpfr是否可以忽略

谢谢
回复 支持 反对

使用道具 举报

发表于 2008-5-22 13:40:35 | 显示全部楼层
上面提到“lz 配置编译gcc时是否选中fortran,不然GCC-4.0.2不会提示mpfr,检查一下gcc配置参数是否正确。”
其前提条件是你前面的步骤都正确。
编译gcc-4.3之前版本c/c++编译器,mpfr、gmp支持不是强制选项。

现在可以确认你gcc配置没有问题,那么问题只能出在前面的步骤。
没有简单方法,只有老老实实从头开始查,特别是各种路径设置。

./a.out不能执行也说明工具链有问题。

lz 参考的是什么资料,怎么还有gmp-4.2.2。

你如果真的喜欢mpfr、gmp,完全可以在系统自举后,重新编译带mpfr、gmp支持的gcc/g++。
回复 支持 反对

使用道具 举报

发表于 2008-5-22 17:14:50 | 显示全部楼层
Post by badworm;1853251

to  地球发动机:
我的第一遍gcc编译如上, 当前在$LFS/tools/lib下有libc.so.6文件,
我不明白你说的动态加载器出了问题是什么意思?

echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep ': $LFS/tools'
[Requesting program interpreter: /tools/lib/ld-linux.so.2]

这个执行结果不能说明回答你说的问题吗?

你说:“mpfr在你的GCC版本下不是必选项。你可以忽略这个警告。”
我不能确定当前的编译的错误,是否可以忽略mpfr,还是a.out的问题。应为这是两个问题,等解决了a.out的问题再看看mpfr是否可以忽略

谢谢

mpfr的警告是可以忽略的。至于a.out的问题,你贴出来的内容还不足以说明它就足以解决动态链接的问题了。比如说,$LFS/tools/lib/ld-linux.so.2有,但/tools/lib/ld-linux.so.2有吗?$LFS/tools/lib/libc.so.6有,/tools/lib/libc.so.6有吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-5-26 11:53:09 | 显示全部楼层
谢谢
to 1987a:
我参考的是: 功能单一,体积小巧的LFS完整版(5M大小的Apache服务器)

to 地球发动机:
我在整个前面的步骤中只少了一步,就是你问我的:

----------------
$LFS/tools/lib/ld-linux.so.2有,但/tools/lib/ld-linux.so.2有吗?$LFS/tools/lib/libc.so.6有,/tools/lib/libc.so.6有吗?
----------------

我在当时认为根目录下的/tools目录只是一个链接目录,所以我就没有创建这个连接,而是把所有的/tools的目录替换为/mnt/lfs/tools, 难道这样有问题吗?
回复 支持 反对

使用道具 举报

发表于 2008-5-26 17:56:35 | 显示全部楼层
Post by badworm;1855150
谢谢
to 1987a:
我参考的是: 功能单一,体积小巧的LFS完整版(5M大小的Apache服务器)

to 地球发动机:
我在整个前面的步骤中只少了一步,就是你问我的:

----------------
$LFS/tools/lib/ld-linux.so.2有,但/tools/lib/ld-linux.so.2有吗?$LFS/tools/lib/libc.so.6有,/tools/lib/libc.so.6有吗?
----------------

我在当时认为根目录下的/tools目录只是一个链接目录,所以我就没有创建这个连接,而是把所有的/tools的目录替换为/mnt/lfs/tools, 难道这样有问题吗?


当然有问题。要是没有这个目录,那么就无法找到动态链接加载器,无法找到许多文件。
这个可以说是整个LFS里面非常关键的一个步骤,你居然把它省略了!?

为什么需要这个链接?因为要让程序在后面chroot之前和之后都可以运行。这样就要chroot前后,/tools目录下有相同的内容。这下你就能理解为什么需要链接了吧。

在各LFS分支中,只有CLFS-SYSROOT是不需要创建根目录下的链接的。但CLFS-SYSROOT里面,宿主的工具和目标的工具分得很清楚,不会存在一个程序在两个环境都要运行的情况。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-5-27 10:22:27 | 显示全部楼层
to 地球发动机:
非常感谢你的解答,关于/tools的目录链接我确实犯了错误。

但是我现在还没有到chroot哪一步,此外,我替换了编译lfs过程中所有根目录下的/tools为/mnt/lfs/tools,按我的理解,应该在chroot之后才会出现‘无法找到动态链接加载器’和a.out文件不能运行的问题吧? 因为chroot之前我的路径都指向/mnt/lfs/tools, 在那里有所有的库文件。
不知你的看法呢?
回复 支持 反对

使用道具 举报

发表于 2008-5-27 18:59:26 | 显示全部楼层
Post by badworm;1855490
to 地球发动机:
非常感谢你的解答,关于/tools的目录链接我确实犯了错误。

但是我现在还没有到chroot哪一步,此外,我替换了编译lfs过程中所有根目录下的/tools为/mnt/lfs/tools,按我的理解,应该在chroot之后才会出现‘无法找到动态链接加载器’和a.out文件不能运行的问题吧? 因为chroot之前我的路径都指向/mnt/lfs/tools, 在那里有所有的库文件。
不知你的看法呢?


你把工具链调整得比较奇怪,直接在SPECS里面就写上$LFS了,这样可能导致随后的GCC第二遍无法生成正确的SPECS。这是我的猜测。

你还是要按照书上说明一步一步来吧!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表