我正在 Visual Studio 中开发 C++ 应用程序,在 x64 系统上使用 WSL 和 G++ 进行编译
抱歉,如果这很明显,但我是 Linux 开发应用程序的新手
/proc/cpuinfo 标志:
fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm avx512f avx512dq rdseed adx smap clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 arat pku ospke md_clea
这是当我使用“./program.out”运行可执行文件时得到的结果:
bash: ./program.out: cannot execute binary file: Exec format error
并使用“sudo ./program.out”:
./program.out: 1: ./program.out: 1: not found
./program.out: 1: ./program.out: ELF: not found
./program.out: 1: ./program.out: A��878G8G����DD: not found
./program.out: 1: ./program.out: A: not found
./program.out: 1: ./program.out: 1: not found
: No such filents.out: 1: ./BeXCoolAccounts.out: cannot open
./program.out: 2: ./program.out: @!l: not found
: No such filents.out: 1: ./BeXCoolAccounts.out: cannot open �GJ�V�JA
./program.out: 1: ./program.out: %@@@����nnppp-[-[����X�XA1A: not found
./program.out: 2: ./program.out: Syntax error: end of file unexpected
和“文件./program.out”:
./program.out: ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), no program header, missing section headers
当我寻找解决方案时,我尝试了“ldd ./program.out”:
not a dynamic executable
和“strace ./program.out”:
execve("./program.out", ["./program.out"], 0x7ffcc5b8b100 /* 27 vars */) = -1 ENOEXEC (Exec format error)
strace: exec: Exec format error
+++ exited with 1 +++
我还在可执行文件上使用了 chmod a+x,但仍然没有任何结果
答案1
没有程序头,缺少节头
不是动态可执行文件
我不知道你是如何编译它的,但生成的文件很可能是不是有效的 Linux 可执行文件。例如,如果您使用文本模式通过 FTP 复制它,则可能会发生这种情况。或者您在文本编辑器中编辑了生成的文件。
file
Fedora 33 上有效可执行文件的返回结果如下:
file `which file`
/bin/file: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=b8d5ba190593ec9e03e602d75dc0ea24a27a5cdb, for GNU/Linux 3.2.0, stripped
或者在 Ubuntu 18.04 上:
$ file `which file`
/usr/bin/file: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=2b26928f841d92afa31613c2c916a3abc96bbed8, stripped