前言:我必须承认我是Ubuntu的完全入门者,但请保持温柔。
所以我有这个程序,我们在uni的计算机实验室中完成了这项工作,并在该程序中完美运行。当我尝试在家用计算机上进行编译时,它显示以下信息:
Compiling project
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/bin/ld: error:
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/crt0.o: Conflicting CPU architectures 12/1
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/bin/ld: failed to merge target specific data of file /usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/crt0.o
collect2: error: ld returned 1 exit status
Makefile:34: recipe for target 'default' failed
make: *** [default] Error 1
在此之前,我只是在程序和makefile所在的文件夹中调用make。由于它在学校计算机上可以正常工作,并且出现“冲突的CPU体系结构”错误,因此我倾向于认为Ubuntu或GCC安装存在错误。
Ubuntu版本:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
FAMILY := nrf51
SOURCES := main.c uart.c
BUILD_DIR := .build_system
LINKER_SCRIPT := $(BUILD_DIR)/linker_script.ld
GNU_PREFIX := arm-none-eabi
CC := $(GNU_PREFIX)-gcc
OBJCOPY := $(GNU_PREFIX)-objcopy
OBJDUMP := $(GNU_PREFIX)-objdump
QUIET := @
## Compiler flags
# CPU specific
CFLAGS += -mcpu=cortex-m0 -mthumb -mabi=aapcs -mfloat-abi=soft
# Get linker optimization for free
CFLAGS += -ffunction-sections -fdata-sections --short-enums
CFLAGS += -fno-strict-aliasing -fno-builtin
# Good pracice
CFLAGS += -Wall -Werror -std=gnu99
# CFLAGS += -ggdb -Og / -O0 / -O3 etc
## Linker flags
CFLAGS += --specs=nosys.specs -Wl,--gc-sections -T $(LINKER_SCRIPT)
# or --specs=nano.specs -lc -lnosys
SOURCES += $(BUILD_DIR)/system_nrf51.c
SOURCES += $(BUILD_DIR)/gcc_startup_nrf51.S
.PHONY: default flash clean
default:
@echo Compiling project
$(QUIET)$(CC) $(CFLAGS) $(SOURCES) -o $(BUILD_DIR)/main.elf
@echo Creating hex file
$(QUIET)$(OBJCOPY) -O ihex $(BUILD_DIR)/main.elf $(BUILD_DIR)/main.hex
flash:
nrfjprog -f $(FAMILY) --sectorerase --program $(BUILD_DIR)/main.hex
nrfjprog -f $(FAMILY) --reset
erase:
nrfjprog -f $(FAMILY) --eraseall
clean:
$(QUIET)rm $(BUILD_DIR)/main.{elf,hex}
答案 0 :(得分:0)
您的makefile具有特定于arm的硬编码工具链。您可以对其进行一些微调,使其可以在x86上运行:
FAMILY := nrf51
SOURCES := main.c uart.c
BUILD_DIR := .build_system
LINKER_SCRIPT := $(BUILD_DIR)/linker_script.ld
arch = $(shell uname -m)
# Intel 64-bit machine?
ifeq ($(arch),x86_64)
CC := gcc
OBJCOPY := objcopy
OBJDUMP := objdump
else
# Default to arm
GNU_PREFIX := arm-none-eabi
CC := $(GNU_PREFIX)-gcc
OBJCOPY := $(GNU_PREFIX)-objcopy
OBJDUMP := $(GNU_PREFIX)-objdump
# ARM CPU specific
CFLAGS += -mcpu=cortex-m0 -mthumb -mabi=aapcs -mfloat-abi=soft
endif
QUIET := @
...
请注意,我将CFLAGS放入条件中,它们也是特定于手臂的。 如果要在其他CPU架构上运行,可以进行类似的调整。