[英]"bash: ./main: cannot execute binary file: Exec format error" using wsl2:Ubuntu on windows 11 Visual Studio Code
#include <stdio.h>
int main()
{
printf("Hello World");
return 0;
}
I build by:我通过以下方式构建:
gcc -Wall -ansi -pedantic -c main.c -o main
uname -m
gives "x86_64". uname -m
给出“x86_64”。
After compiling file main
gives:编译
file main
后给出:
main: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
strace./main
gives: strace./main
给出:
execve("./main", ["./main"], 0x7ffc779cf7c0 /* 33 vars */) = -1 EACCES (Permission denied)
strace: exec: Permission denied
+++ exited with 1 +++"
You did only compile, but not link the program.您只编译了程序,但没有链接程序。 Unlinked object files cannot be executed.
无法执行未链接的 object 文件。
Change your build command to:将构建命令更改为:
gcc -Wall -ansi -pedantic main.c -o main
Note the missing -c
.请注意缺少的
-c
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.