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

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

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 )

Related

MAKEFILE,COMPILE,GCC and LINKING

I am getting this error while running make file to link the .o files.
command is $make build PLATFORM=HOST or $make build PLATFORM=MSP432,both gives the same error.
gcc main.o memory.o -DHOST -g -O0 -std=c99 -Wall -Werror -I../src/ -I../include/CMSIS/ -I../include/msp432/ -I../include/common/ -I../ -Wl,-Map=c1m2.map -L/usr/local/lib -T ../msp432p401r.lds -o c1m2.out
/usr/bin/ld: c1m2.out: Not enough room for program headers, try linking with -N
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Makefile:79: recipe for target 'c1m2.out' failed
make: *** [c1m2.out] Error 1
and my makefile script:
include sources.mk
# Platform Overrides
PLATFORM = HOST
# Architectures Specific Flags
LINKER_FILE = msp432p401r.lds
CPU = cortex-m4
ARCH = armv7e-m
SPECS = nosys.specs
# Compiler Flags and Defines
# Conditional statements to choose the platform(host/msp432) else invalid platform message is diplayed.
ifeq ($(PLATFORM),HOST)
CC = gcc
CFLAGS = -DHOST
LD = ld
else
CC = arm-none-eabi-gcc
CFLAGS = -DMSP432 -mcpu=$(CPU) -march=$(ARCH) --specs=$(SPECS) -mfloat-abi=hard -mfpu=fpv4-sp-d16
LD = arm-none-eabi-ld
endif
TARGET = c1m2
LDFLAGS = -Wl,-Map=$(TARGET).map -T ../msp432p401r.lds
CPPFLAGS = -g -O0 -std=c99 -Wall -Werror $(INCLUDES)
OBJS = $(SRCS:.c=.o)
%.o : %.c
$(CC) -c $< $(CFLAGS) $(CPPFLAGS) -o $#
pre = $(SRCS:.c=.i)
%.i : %.c
$(CC) -c $< $(CFLAGS) $(CPPFLAGS) -E -o $#
asem =$(SRCS:.c=.asm):
%.asm : %.c
$(CC) -c $< $(CFLAGS) $(CPPFLAGS) -S -o $#
.PHONY: build
build: all
.PHONY: all
all: $(TARGET).out
$(TARGET).out: $(OBJS)
$(CC) $(OBJS) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $#
.PHONY: clean
clean:
rm -f $(OBJS) $(pre) $(asem) $(TARGET).out $(TARGET).map
I have created this for running both in HOST and the given processor(MSP432),please don't bother poor formatting.

arm-none-gcc-ld error : cannot find the object file even though it exists with the proper path

So this is a snippet from my makefile to build my target:
#include header files directory
vpath %.h = include
vpath %.o = obj
#create a list of *.c from the source directory
SRC = $(wildcard src/*.c)
OBJ = $(SRC:src/%.c=%.o)
main.elf: $(OBJ)
$(CC) $(LDFLAGX) $(addprefix obj/,$(OBJ)) -o $#
%.o : %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c $^ -o obj/$#
my project directory is as follows:
srcdir
+---include
+---obj
\---src
Here's the output I'm getting:
arm-none-eabi-gcc -Iinclude -mcpu=cortex-m3 -mthumb -std=gnu11 -O0 -g -Wall -c src/RCC.c -o obj/RCC.o
arm-none-eabi-gcc -Iinclude -mcpu=cortex-m3 -mthumb -std=gnu11 -O0 -g -Wall -c src/SPI.c -o obj/SPI.o
arm-none-eabi-gcc -Iinclude -mcpu=cortex-m3 -mthumb -std=gnu11 -O0 -g -Wall -c src/main.c -o obj/main.o
arm-none-eabi-gcc -Iinclude -mcpu=cortex-m3 -mthumb -std=gnu11 -O0 -g -Wall -c src/startup.c -o obj/startup.o
arm-none-eabi-gcc -Iinclude -mcpu=cortex-m3 -mthumb -std=gnu11 -O0 -g -Wall -c src/timer.c -o obj/timer.o
arm-none-eabi-gcc -Iinclude -mcpu=cortex-m3 -mthumb -std=gnu11 -O0 -g -Wall -c src/usart.c -o obj/usart.o
arm-none-eabi-gcc -Xlinker -T -Xlinker lscript.ld -Xlinker -nostdlib -Xlinker -Map=main.map obj/RCC.o obj/SPI.o obj/main.o obj/startup.o obj/timer.o obj/usart.o -o main.elf
c:/program files (x86)/gnu arm embedded toolchain/9 2020-q2-update/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: cannot find startup.o
collect2.exe: error: ld returned 1 exit status
make.exe": *** [main.elf] Error 1
So the startup.o exists in obj/ folder and the path has also been specified in the recipe so What is going wrong here?
I have been struggling to create my own makefile due to tons of such errors and even after trying out numerous tutorials and examples which may solve a problem, another new one pops up every now and then, is there any more convenient way to build such projects that does not cause me so much trouble?

Can't compile a C program in Windows 7 with MinGW make

I want to compile a C program from GitHub on Windows 7 and get an error that a file is not found. I have installed MinGW Make and its dependancies. I think maybe this program is only intended to run on Linux.
The Console output:
E:\work-c\iso2opl-clone\iso2opl>make
gcc -std=gnu99 -pedantic -usr\include -usr\local\inc
lude -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -c isofs.c -o isofs.o
process_begin: CreateProcess(NULL, gcc -std=gnu99 -pedantic -F:\programs\mingw\i
nclude -F:\programs\mingw\local\include -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SO
URCE -c isofs.c -o isofs.o, ...) failed.
make (e=2): Le fichier spécifié est introuvable.
make: *** [isofs.o] Erreur 2
the makefile:
CC = gcc
CFLAGS = -std=gnu99 -pedantic -I/usr/include -I/usr/local/include -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
#CFLAGS += -DDEBUG
ifeq ($(_WIN32),1)
CFLAGS += -D_WIN32
endif
OBJS = isofs.o \
iso2opl.o
all: $(TARGET)
rm-elf:
-rm -f $(TARGET) $(OBJS)
$(TARGET): $(OBJS)
$(CC) $(OBJS) -o $(TARGET) $(LIBS)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $#
%.o: %.cpp
$(CC) $(CFLAGS) -c $< -o $#
clean:
rm -r $(OBJS) $(TARGET)
I don't know maybe the paths are wrongs.
Best Regards
Try to run the make in the MSYS2 shell (https://www.msys2.org/). I was able to build the sources from https://github.com/arcadenea/iso2opl without issue.

GNU make doesn't include headerfile

I have been searching for 6 hours and I can't seem to find the issue with this GNU make file, everytime I try to compile by main.o by the order
make main.o
it gives me this error:
arm-none-eabi-gcc -c main.c -mcpu=cortex-m4 -mthumb --
specs=nosys.specs -Wall -Werror -g -O0 -std=c99 -o main.o
main.c:23:22: fatal error: platform.h: No such file or directory
#include "platform.h"
^
compilation terminated.
Makefile:52: recipe for target 'main.o' failed
make: *** [main.o] Error 1
makefile:
include sources.mk
# Platform Overrides
PLATFORM = MSP432
# Architectures Specific Flags
LINKER_FILE = msp432p401r.lds
CPU = cortex-m4
ARCH = thumb
SPECS = nosys.specs
# Compiler Flags and Defines
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
TARGET = c1m1
LDFLAGS = -Wl,-Map=$(TARGET).map -T $(LINKER_FILE)
CFLAGS = -mcpu=$(CPU) -m$(ARCH) --specs=$(SPECS) -Wall -Werror -g -O0 -std=c99
CPPFLAGs =
.PHONY: all
all: $(TARGET).out
.PHONY: clean
clean:
rm -f $(OBJS) $(TARGET).out $(TARGET).map
%.o : %.c
$(CC) -c $< $(CFLAGS) -o $#
OBJS = $(SOURCES:.c=.o)
$(TARGET).out: $(OBJS)
$(CC) $(OBJS) $(CFLAGS) $(LDFLAGS) -o $#
sources.mk:
# Add your Source files to this variable
SOURCES =./main.c \
./memory.c \
./startup_msp432p401r_gcc.c \
./system_msp432p401r.c \
./interrupts_msp432p401r_gcc.c
# Add your include paths to this variable
INCLUDES =-I./include/CMSIS \
-I./include/common \
-I./include/msp432
here's my code on github:
github repository
You have not used the INCLUDES macro in makefile's CFLAGS macro. Consequently the arm-none-eabi-gcc ... command line does not specify the include paths to the compiler (or strictly the pre-processor).
CFLAGS = -mcpu=$(CPU) -m$(ARCH) --specs=$(SPECS) $(INCLUDES) -Wall -Werror -g -O0 -std=c99
^^^^^^^^^^^

stm32 arm-none-eabi-gcc link library

Hello I need to compute logarithms on my stm32. I use arm-none-eabi-gcc. When I add -L/opt/tools/Sourcery_G++_Lite/arm-none-eabi/lib/ in my Makefile microcontroller stop to work. Unfortunately I can't debug my program because there is no debag pins on my device and I load program to flash via bootloader. I not use any math functioins from libraries - i just add library path to Makefile.
Here is my full makefile:
OUTPUTDIR = $(BUILDDIR)/../../output
DEPDIR = $(BUILDDIR)/.dep
PWD = $(shell pwd)
COMMONFLAGS = -mcpu=cortex-m3 -mthumb -ggdb3
CFLAGS += $(COMMONFLAGS) -Os $(INCLUDES) -I.
CFLAGS += -std=c99 -Wall -Wextra -static -fdata-sections -ffunction-sections -fno-hosted -fno-builtin
CFLAGS += -nostdlib -nodefaultlibs
CFLAGS += -mapcs-frame -msoft-float
CFLAGS += -MD -MP -MF $(DEPDIR)/$(#F).d
LDFLAGS = $(COMMONFLAGS) -static
LDFLAGS += -fno-exceptions -ffunction-sections -fdata-sections
LDFLAGS += -static -Xlinker --gc-sections
#LDFLAGS += -L/opt/tools/dima/Sourcery_G++_Lite/arm-none-eabi/lib/
ASFLAGS = $(COMMONFLAGS)
CFLAGS += -DUSE_STDPERIPH_DRIVER
CROSS = /opt/tools/Sourcery_G++_Lite/bin/arm-none-eabi
GCC = $(CROSS)-gcc
AS = $(CROSS)-as
SIZE = $(CROSS)-size
OBJCOPY = $(CROSS)-objcopy
OBJDUMP = $(CROSS)-objdump
NM = $(CROSS)-nm
COBJ = $(addprefix $(BUILDDIR)/, $(CSRC:.c=.c.o))
ASMOBJ = $(addprefix $(BUILDDIR)/, $(ASMSRC:.s=.s.o))
OBJ = $(COBJ) $(ASMOBJ)
V = $(if $(VERBOSE), , #)
all: prebuild $(BUILDDIR)/$(TARGET).elf $(LDSCRIPT)
#$(SIZE) $(BUILDDIR)/$(TARGET).elf
#$(OBJCOPY) -O binary $(BUILDDIR)/$(TARGET).elf $(BUILDDIR)/$(TARGET).bin
#$(OBJCOPY) -O ihex $(BUILDDIR)/$(TARGET).elf $(BUILDDIR)/$(TARGET).hex
#$(OBJDUMP) -h -S -z $(BUILDDIR)/$(TARGET).elf > $(BUILDDIR)/$(TARGET).lss
#$(NM) -n $(BUILDDIR)/$(TARGET).elf > $(BUILDDIR)/$(TARGET).sym
#mkdir -p $(OUTPUTDIR)
#cp $(BUILDDIR)/$(TARGET).bin $(OUTPUTDIR)
#echo =======================================================================
$(BUILDDIR)/$(TARGET).elf: $(OBJ)
#echo Linking $#
$(GCC) $(LDFLAGS) -T $(PWD)/$(LDSCRIPT) -o $# $(OBJ) -lm
$(COBJ): $(BUILDDIR)/%.c.o : %.c
#echo Compiling $<
#-mkdir -p $(#D)
$(GCC) $(CFLAGS) -c $< -o $#
$(ASMOBJ): $(BUILDDIR)/%.s.o : %.s
#echo Assembling $<
#-mkdir -p $(#D)
$(V)$(AS) $(ASFLAGS) -c ./$< -o $#
-include $(shell mkdir -p $(DEPDIR) 2>/dev/null) $(wildcard $(DEPDIR)/*)
.PHONY: clean output
clean:
rm -rf $(BUILDDIR)
What i do wrong? Thanks.
Whith this library dir you will simply link against the wrong set of files in multilib, and end up linking with ARM code while your MCU can only execute THUMB code. The correct set of files should be in the thumb2 subdirectory for Cortex M3 µC.
Note that Sourcery G++ lite will auto-magically add the correct library dir when using arm-none-eabi-gcc to link, which your Makefile seems to do already.
You really shouldn't link libm.a manually and you really shouldn't hardcode library path manually... This all gets done automatically (and correctly) if you use arm-none-eabi-gcc (or -g++) to link and give proper flags (-mcpu and -mthumb). So just drop all these paths and "-lm" and it must work. You could try one of my example project for ARM microcontrollers - the settings in the makefiles (and linker scripts) make all of this work just fine - with no user intervention. http://www.freddiechopin.info/en/download/category/6-examples
Also - I think part of the problem may be in these flags you use: -fno-hosted -fno-builtin -nostdlib -nodefaultlibs - the last one especially prevents this automatic linking of libm.a.

Resources