gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 12:13:11 25 4
gpt4 key购买 nike

我是 Linux 的新手。我正在尝试为在线类(class)编译代码。 /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) 在哪里?

最佳答案

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

关于c++ - bash:无法执行二进制文件:Exec 格式错误,即使二进制文件和 Linux 是 64 位的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34587364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com