【问题标题】:File compiled by gcc on a musl toolchain not found by /bin/sh由 gcc 在 /bin/sh 找不到的 musl 工具链上编译的文件
【发布时间】:2020-07-25 05:58:39
【问题描述】:

我在 dockerhub 上试用了 muslcc 映像,但无法运行已编译的 Hello World 程序。

我使用的图像是:muslcc/i686:x86_64-linux-musl(找到here)。我加载图像:

docker run -it --rm -v /path/to/local:/var muslcc/i686:x86_64-linux-musl

这样我就可以在本地机器上编码,并在 musl 映像上编译和测试。


我正在编译的程序是一个基本的hello world:

#include<stdio.h>

int main(void){
    puts("Hello world.");
    return 0;
}

此文件保存为helloworld.c

我运行gcc -Wall helloworld.c 并在同一目录中获取a.out。做ls -l给了我:

total 1068
-rwxr-xr-x    1 root     root          7584 Jul 25 05:41 a.out
-rw-r--r--    1 root     root            76 Jul 25 05:27 helloworld.c

当我尝试使用./a.out 运行a.out 时,我得到:

/bin/sh: ./a.out: not found

我也尝试指定一个输出文件,以防这是默认输出的一些问题,但没有运气。我也尝试过使用绝对路径,例如 /var/a.out,但也没有运气。

-- 编辑:

  1. 我已经检查过了,./ 符号在 $PATH 中

【问题讨论】:

    标签: gcc musl


    【解决方案1】:

    好的,我通过将-static 标志添加到 gcc 来修复它:

    gcc -static input.c -o output.out
    

    【讨论】:

      猜你喜欢
      • 2020-11-16
      • 1970-01-01
      • 2014-09-12
      • 2023-01-07
      • 1970-01-01
      • 1970-01-01
      • 2022-08-09
      • 1970-01-01
      • 2020-02-03
      相关资源
      最近更新 更多