bash:./helloworld_s:没有这样的文件或目录.该文件显然在那里 [英] bash: ./helloworld_s: no such file or directory. The file is clearly there

查看:35
本文介绍了bash:./helloworld_s:没有这样的文件或目录.该文件显然在那里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对bash并不陌生,但这是我第一次看到这种情况.

I'm not unfamiliar with bash, but this is the first time I have ever seen this happen.

[OP@localhost linking]$ ls
helloworld-lib.o  helloworld-lib.s  helloworld_s
[OP@localhost linking]$ ./helloworld_s
bash: ./helloworld_s: No such file or directory

我在测试链接器 ld 时发生了此错误. helloworld-lib.s 的内容是:

This error occurred while I was testing the linker, ld. The contents of helloworld-lib.s are:

[OP@localhost linking]$ cat helloworld-lib.s 
    .section .data
helloworld:
    .ascii "Hello, world!\n\0"

    .section .text
    .globl _start

_start:
    mov $helloworld, %rdi
    call printf

    mov $0, %rdi
    call exit

此文件 helloworld_s 的生​​成如下.

This file helloworld_s was produced as follows.

[OP@localhost linking]$ as helloworld-lib.s -o helloworld-lib.o
[OP@localhost linking]$ ld -lc helloworld-lib.o -o helloworld_s

IDK(如果其中任何相关信息).仅供参考,如果我尝试运行其他文件,我只会得到一个被拒绝的权限(如预期的那样).有什么想法吗?

IDK if any of this information is relevant. As an FYI, if I attempt to run the other files, I just get a permission denied (as expected). Any ideas?

根据建议,这是 ls -l <​​/code>的输出:

as suggested, here is the output of ls -l:

[OP@localhost linking]$ ls -l
total 88
-rw-rw-r--. 1 OP OP   968 Mar 23 18:40 helloworld-lib.o
-rw-rw-r--. 1 OP OP   159 Mar 23 18:40 helloworld-lib.s
-rwxrwxr-x. 1 OP OP 14384 Mar 23 18:41 helloworld_s

这是 id 的输出:

[OP@localhost linking]$ id
uid=1000(OP) gid=1000(OP) groups=1000(OP),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

有关答案,请参阅评论.请参见此处

for answer, see comments. See here

推荐答案

如redhat错误

As explained in redhat bug #868662 , the recommanded way to link is to let gcc call ld like below;

> gcc -nostartfiles helloworld-lib.o -o helloworld_s -lc

这将导致正确的链接;

Which results in correct linking;

> ldd helloworld_s
        linux-vdso.so.1 =>  (0x00007ffd283bf000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fd011b62000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fd011f2f000)

执行正常;

> ./helloworld_s
Hello, world!

为什么ld链接到不存在的/lib/ld64.so.1?
因为这是通用系统的默认设置,而不仅仅是Linux.

Why does ld link to /lib/ld64.so.1 which does not exist ?
Because this is the default setup for a generic system, not only Linux.

这篇关于bash:./helloworld_s:没有这样的文件或目录.该文件显然在那里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆