0

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

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

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
4

1 回答 1

0

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

gcc -static input.c -o output.out
于 2020-08-04T02:37:27.020 回答