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:
你好,我需要在stm32上计算对数。我使用arm-none-eabi-gcc。当我在我的Makefile微控制器中添加-L/opt/tools/Sourcery_G+ _Lite/arm-none-eabi/lib/时,就停止工作了。不幸的是,我无法调试我的程序,因为我的设备上没有debag引脚,我通过引导加载程序将程序加载到flash中。我没有使用库中的任何数学函数—我只是向Makefile添加了库路径。这是我的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.
我做错了什么吗?谢谢。
2 个解决方案
#1
2
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.
在这个库目录中,您将直接链接到multilib中的错误文件集,并最终链接到ARM代码,而您的MCU只能执行拇指代码。正确的文件集应该在皮层M3µC thumb2子目录的。
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.
注意,在使用arm-none-eabi-gcc链接时,Sourcery G+ lite将自动添加正确的库dir,您的Makefile似乎已经这样做了。
#2
1
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
你真的不应该链接libm。手动和你真的不应该硬编码库路径手动…如果您使用arm-none-eabi-gcc(或-g++)链接并提供适当的标志(-mcpu和-mthumb),那么所有这些都将自动完成(并正确地)。所以只要去掉这些路径和-lm,它就会工作。您可以尝试我的ARM微控制器的一个示例项目——makefile(和链接脚本)中的设置使所有这些工作都很好——不需要用户干预。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.
另外,我认为部分问题可能出现在您使用的这些标志中:-fno托管-fno-内置-nodefaultlibs -最后一个特别防止libm.a的自动链接。
#1
2
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.
在这个库目录中,您将直接链接到multilib中的错误文件集,并最终链接到ARM代码,而您的MCU只能执行拇指代码。正确的文件集应该在皮层M3µC thumb2子目录的。
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.
注意,在使用arm-none-eabi-gcc链接时,Sourcery G+ lite将自动添加正确的库dir,您的Makefile似乎已经这样做了。
#2
1
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
你真的不应该链接libm。手动和你真的不应该硬编码库路径手动…如果您使用arm-none-eabi-gcc(或-g++)链接并提供适当的标志(-mcpu和-mthumb),那么所有这些都将自动完成(并正确地)。所以只要去掉这些路径和-lm,它就会工作。您可以尝试我的ARM微控制器的一个示例项目——makefile(和链接脚本)中的设置使所有这些工作都很好——不需要用户干预。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.
另外,我认为部分问题可能出现在您使用的这些标志中:-fno托管-fno-内置-nodefaultlibs -最后一个特别防止libm.a的自动链接。