【发布时间】: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