我正在使用GNU / Linux 64位Oracle VM来编译一个简单的c程序main.c:
int main(){ return 0; }
gcc命令是:gcc -c main.c -o output
运行时:./ output,会导致错误:“无法执行二进制文件:执行格式错误”
-c
标志告诉gcc
生成一个目标文件。对象文件不可执行,而是输入到用于创建可执行文件的链接器。
要么放下-c
标志:
gcc main.c -o output
或者构建目标文件然后链接它:
gcc -c main.c
gcc main.o -o output
有关GCC命令行参数的更多信息,请使用read the documentation获取您的GCC版本。