user3583807
user3583807

Reputation: 800

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.

Upvotes: 1

Views: 6646

Answers (2)

Freddie Chopin
Freddie Chopin

Reputation: 8860

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.

Upvotes: 1

Turbo J
Turbo J

Reputation: 7691

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.

Upvotes: 2

Related Questions