Search code examples
cmacosmakefilecompiler-errorsarm

Trouble with arm-none-eabi-gcc during compilation on Mac OS (M1)


  • Context:

I'm using a Mac OS Monterey (12.5.1) with M1 pro processor

The last version of Xcode is installed

I'm trying to build an image to used it inside a raspberry pi and trying to interact with a Piface LED screen. With the PI OS, I load my own kernel (.img) in the config.txt

I'm trying to compile c with (gcc) arm-none-eabi by Makefile :

MAINFILE = a2p1
OBJS    =  lib/piface.o
OBJS    += lib/rpi-gpio.o lib/rpi-armtimer.o lib/rpi-interrupts.o lib/rpi-systimer.o 
OBJS    += lib/startup.o lib/syscalls.o 
OBJS    += $(MAINFILE).o

ELF     = $(MAINFILE).elf
MAIN    = $(MAINFILE).img

CROSS   = arm-none-eabi-
CC      = $(CROSS)gcc
AS      = $(CROSS)as
SIZE    = $(CROSS)size
OCOPY   = $(CROSS)objcopy

CFLAGS  = -march=armv8-a+crc -mtune=cortex-a53 -mfpu=vfp -mfloat-abi=soft -ffunction-sections -fdata-sections -fno-common -g -std=gnu99 -Wall -Wextra -Os -Ilib -DRPI3=1 -DIOBPLUS=1

LFLAGS  = -static -nostartfiles -lc -lgcc -specs=nano.specs -Wl,--gc-sections -lm
LSCRIPT = lib/rpi3.ld

LDFLAGS += -u _printf_float

.PHONY: all clean run

all: $(MAIN)

%.o: %.c
    $(CC) $(CFLAGS) -c -o $@ $^

$(ELF): $(OBJS)
    $(CC) -T $(LSCRIPT) $(CFLAGS) $(LFLAGS) $(LDFLAGS) -o $@ $^
    $(SIZE) $@
    
$(MAIN): $(ELF)
    $(OCOPY) $< -O binary $@

clean:
    rm -f $(MAIN) $(ELF) $(OBJS)

run: $(MAIN)

I've installed arm-none-eabi-gcc using 'port' this way :

sudo port install arm-none-eabi-gcc

  • Here is my errors:

can not find -lc_nano : No such file or directory

/opt/local/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/bin/ld : can not find -lg_nano : No such file or directory

/opt/local/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/bin/ld : can not find -lc_nano : No such file or directory

  • How the error occur : When the compiler is trying to run this (I suppose this is the linking step):

arm-none-eabi-gcc -T lib/rpi3.ld -march=armv8-a+crc -mtune=cortex-a53 -mfpu=vfp -mfloat-abi=soft -ffunction-sections -fdata-sections -fno-common -g -std=gnu99 -Wall -Wextra -Os -Ilib -DRPI3=1 -DIOBPLUS=1 -static -nostartfiles -lc -lgcc -specs=nano.specs -Wl,--gc-sections -lm -u _printf_float -o a2p1.elf lib/piface.o lib/rpi-gpio.o lib/rpi-armtimer.o lib/rpi-interrupts.o lib/rpi-systimer.o lib/startup.o lib/syscalls.o a2p1.o


Solution

  • I got the same issue with the port, remove it and use instead :

    brew install --cask gcc-arm-embedded

    ( https://formulae.brew.sh/cask/gcc-arm-embedded )