linux x86_64 vm gcc错误的可执行输出架构,exec文件格式错误

问题描述 投票:0回答:1

我正在使用GNU / Linux 64位Oracle VM来编译一个简单的c程序main.c: int main(){ return 0; } gcc命令是:gcc -c main.c -o output 运行时:./ output,会导致错误:“无法执行二进制文件:执行格式错误”

Why the gcc compilation results an executable that doesn't correspond to the architecture of the machine(SYSV and not GNU/Linux)? 提前致谢

c linux gcc x86-64 file-format
1个回答
1
投票

-c标志告诉gcc生成一个目标文件。对象文件不可执行,而是输入到用于创建可执行文件的链接器。

要么放下-c标志:

gcc main.c -o output

或者构建目标文件然后链接它:

gcc -c main.c
gcc main.o -o output

有关GCC命令行参数的更多信息,请使用read the documentation获取您的GCC版本。

© www.soinside.com 2019 - 2024. All rights reserved.