简体   繁体   English

“bash: ./main: 无法执行二进制文件:执行格式错误”在 windows 上使用 wsl2:Ubuntu 11 Visual Studio 代码

[英]"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.

相关问题 bash: ./remoteServer .o: 无法执行二进制文件: Exec 格式错误 - bash: ./remoteServer .o: cannot execute binary file: Exec format error ./abc.o: 无法执行二进制文件:Exec 格式错误 - ./abc.o: cannot execute binary file: Exec format error 将 c 程序编译为 mips 二进制文件后出现“无法执行二进制文件:执行格式错误” - “cannot execute binary file: Exec format error”occured after compile c program to mips binary file 我的C程序无法运行`无法执行二进制文件:执行格式错误` - My C program fails to run with `cannot execute binary file: Exec format error` bash:无法执行二进制文件 - bash: cannot execute binary file 在 Visual Studio Code (Windows) 中运行 C 文件没有错误 - #include stdio.h 无法打开源文件 - Running C file in Visual Studio Code (Windows) without error - #include stdio.h cannot open source file 使用 Visual Studio 代码在 ubuntu 中编写 C 程序 - C program in ubuntu using visual studio code 从Bash调用Java时无法执行二进制文件 - Cannot execute binary file when calling Java from Bash 无法启动程序,找不到指定的文件,Visual Studio 11 - Unable to start program, cannot find the file specified, Visual Studio 11 在Windows上使用Visual Studio Code调试C - Debugging C using Visual Studio Code on Windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM