bash:即使二进制和Linux是64位的,也无法执行二进制文件:Exec格式错误



我对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

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

该文件不是可执行文件。例如,尝试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中的ELF文件是一个需要链接才能生成可执行文件的对象文件(通常,对象文件将包含链接时解析的未解析符号)。其他常见的风格是共享对象(即.so文件)和核心转储。每种口味都有不同的使用方式。

最新更新