2016-01-04 110 views
2

我是Linux的新手。我正在嘗試爲在線課程編譯代碼。在/home/MyName/Desktop/Cplusplus-Advanced-Source-Code/cplusplus-advanced-source-code/BitmapFileHeaders/Debug生成文件是如下:bash:無法執行二進制文件:儘管二進制和Linux是64位,但執行格式錯誤

-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: [email protected]' 
    @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: [email protected]' 
    @echo ' ' 

# Other Targets 
clean: 
    -$(RM)  $(CC_DEPS)$(C++_DEPS)$(EXECUTABLES)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(CPP_DEPS)$(C_DEPS) BitmapFileHeaders 
    [email protected] ' ' 

.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)是哪裏?

+4

'Fractal.o'只是'Fractal.cpp'的目標文件,而不是整個程序。我一眼就沒有完全理解你的makefile,但你基本上正在嘗試運行一箇中間構建文件。 – BoBTFish

+0

它看起來像可執行文件被稱爲「BitmapFileHeaders」。在高級版之前,你應該至少做一個基本課程。 – molbdnilo

+0

你怎麼知道「BitmapFileHeaders」是可執行文件? – user5739619

回答

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文件)和核心轉儲。每種口味都以不同的方式使用。

相關問題