简体   繁体   English

在Ubuntu上使用Makefile编译时出现问题

[英]Problem compiling using makefile on Ubuntu

PREFACE: I gotta admit that I am a complete noob to Ubuntu and all its quirks, so please be gentle. 前言:我得承认我对Ubuntu及其所有怪癖完全陌生,所以请保持温柔。

So I've got this program that we use for an assignment we have worked on it at the computer lab at uni - and it works perfectly there. 因此,我有了这个程序,我们在uni的计算机实验室中完成了这项工作,并在该程序中完美运行。 When I try to compile on my home computer It gives me this: 当我尝试在家用计算机上进行编译时,它显示以下信息:

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

Before this I am just calling make in the folder where the program and the makefile is situated. 在此之前,我只是在程序和makefile所在的文件夹中调用make。 Since it works fine on the school computer and I get the "Conflicting CPU architecture" error I am inclined to believe there is an error either with my Ubuntu or the GCC installation. 由于它在学校计算机上可以正常工作,并且出现“冲突的CPU体系结构”错误,因此我倾向于认为Ubuntu或GCC安装存在错误。

Ubuntu Version: Ubuntu版本:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:        18.04
Codename:       bionic

Hardinfo产生这个

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}

Your makefile has hard-coded tool-chains specific to arm. 您的makefile具有专用于arm的硬编码工具链。 You could tweak it slightly so that it can work on x86: 您可以对其进行一些微调,使其可以在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 := @

...

Note that I put the CFLAGS inside the condition as well as they are arm specific too. 请注意,我将CFLAGS放入条件中,并且它们也是特定于手臂的。 You can similarly adjust if you want to run on other CPU architectures. 如果要在其他CPU架构上运行,可以进行类似的调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM