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

时间:2016-01-04 08:43:59

标签: c++ linux bash executable

我对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)的位置?

1 个答案:

答案 0 :(得分:2)

该文件不是可执行文件。试试例如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文件)和核心转储。每种口味都以不同的方式使用。

相关问题