Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash: cannot execute binary file: Exec format error even though binary and Linux are 64-bit

I'm pretty new to Linux. I'm trying to compile code for an online course. The makefile in /home/MyName/Desktop/Cplusplus-Advanced-Source-Code/cplusplus-advanced-source-code/BitmapFileHeaders/Debug is as below:

-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

in Debug/src, there is Fractal.o. If I try ./Fractal.o, I get bash: ./Fractal.o: cannot execute binary file: Exec format error . However file Fractal.o gives

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

However, I have Ubuntu 15.10, which is 64-bit, so this should run, right? I didn't write this code, so I don't know the author wrote it like this. Would it help if I could change the format of the binary by locating where $(OBJS) is? If so, how do I locate where $(OBJS) is?

like image 231
user5739619 Avatar asked Aug 01 '26 20:08

user5739619


1 Answers

The file is not executable. Try for example file /bin/ls and it would give:

/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

Note that it explicitely states that it's an executable.

ELF files comes in different flavours, the one you've got in Fractal.o is an object file that will need linking to produce an executable (normally an object file will contain unresolved symbols that would be resolved when linking). Other common flavours are shared objects (ie .so files) and core dumps. Each flavour is used in different ways.

like image 57
skyking Avatar answered Aug 04 '26 10:08

skyking



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!