【问题标题】:bash: cannot execute binary file: Exec format error even though binary and Linux are 64-bitbash:无法执行二进制文件:即使二进制和 Linux 是 64 位,也执行格式错误
【发布时间】:2016-01-04 08:43:58
【问题描述】:

我对 Linux 还是很陌生。我正在尝试为在线课程编译代码。 /home/MyName/Desktop/Cplusplus-Advanced-Source-Code/cplusplus-advanced-source-code/BitmapFileHeaders/Debug中的makefile如下:

-include ../makefile.init

print-%  : ; @echo $* = $($*)


RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include src/subdir.mk
-include subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables 

# All Target
all: BitmapFileHeaders

# Tool invocations
BitmapFileHeaders: $(OBJS) $(USER_OBJS)
    @echo 'Building target: $@'
    @echo 'Invoking: MacOS X C++ Linker'
    g++  -o "BitmapFileHeaders" $(OBJS) $(USER_OBJS) $(LIBS)
#"make print-OBJS", in command prompt, gives:
#OBJS = ./src/Fractal Creator - Hello World.o
    @echo 'Finished building target: $@'
    @echo ' '

# Other Targets
clean:
    -$(RM)     $(CC_DEPS)$(C++_DEPS)$(EXECUTABLES)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(CPP_DEPS)$(C_DEPS) BitmapFileHeaders
    -@echo ' '

.PHONY: all clean dependents
.SECONDARY:

-include ../makefile.targets

Debug/src 中有Fractal.o。如果我尝试./Fractal.o,我会得到bash: ./Fractal.o: cannot execute binary file: Exec format error 。但是file Fractal.o 给出了

Fractal.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

但是,我有 64 位的 Ubuntu 15.10,所以它应该可以运行,对吧?这段代码不是我写的,所以不知道作者是这样写的。如果我可以通过定位$(OBJS) 的位置来更改二进制文件的格式会有所帮助吗?如果是这样,我如何找到$(OBJS) 的位置?

【问题讨论】:

  • Fractal.o 只是Fractal.cpp 的目标文件,而不是整个程序。快速浏览一下我还没有完全理解您的 makefile,但您基本上是在尝试运行中间构建文件。
  • 看起来可执行文件名为“BitmapFileHeaders”。在高级课程之前,您可能应该至少学习一门基础课程。
  • 你怎么知道“BitmapFileHeaders”是可执行文件?

标签: c++ linux bash executable


【解决方案1】:

该文件不是可执行文件。尝试例如file /bin/ls,它会给出:

/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x55f1e005df252708d4c456dcc2c7dccea1006553, stripped

请注意,它明确声明它是一个可执行文件。

ELF 文件有不同的风格,您在Fractal.o 中获得的文件是需要链接以生成可执行文件的目标文件(通常目标文件将包含在链接时将被解析的未解析符号)。其他常见的风格是共享对象(即.so 文件)和核心转储。每种口味都有不同的用途。

【讨论】:

    猜你喜欢
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多