Bash,执行格式错误

Bash,执行格式错误

我正在尝试构建并运行程序。

g++ -c source.cpp -o EIC
chmod u+x EIC
./EIC
bash:./EIC: Can not execute binary file: Exec format error.

file EIC显示:

EIC: ELF 64-bit LSB relocatable, x86-x64, version 1(SYSV), not stripped

uname -a显示:

Linux localhost.localdomain 4.18.0-193.el8.x86_x64 #1 SMP Fri May 8 10:59:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

请告诉我原因是什么。

答案1

man g++

   When you invoke GCC, it normally does preprocessing, compilation,
   assembly and linking.  The "overall options" allow you to stop this
   process at an intermediate stage.  For example, the -c option says not
   to run the linker.  Then the output consists of object files output by
   the assembler.

因此,如果您想g++运行链接器 - 创建可执行文件而不是目标代码文件 - 您应该-c从命令中删除该标志。

相关内容