0

i'm working on arm cortex m4 with make file and gcc-arm-none-eabi on ubuntu. when i add math .h library to my project and try to use log10f , the linker exit with errors.


its be good if help my for solve this problem and suggest source for more study ,thank you.

i used -lm but it didn't has any effect.

make file:



# PROJECT: name of the output file
PROJECT = main

SRCS = $(wildcard src/*.c) \
      $(wildcard libs/*.c)
OBJ = obj/
# OBJS: list of object files
OBJS = $(addprefix $(OBJ),$(notdir $(SRCS:.c=.o)))

#Flag points to the INC folder containing header files
INC = -Iinc 

# LD_SCRIPT: linker script
LD_SCRIPT = ld/GD32f30x.ld


#UTILITY VARIABLES
CC = arm-none-eabi-gcc #compiler
LD = arm-none-eabi-ld #linker
OBJCOPY =arm-none-eabi-objcopy #final executable builder

RM      = rm -rf
MKDIR   = @mkdir -p $(@D) #creates folders if not present


#GCC FLAGS
CFLAGS = -ggdb -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 
CFLAGS +=  -mfloat-abi=softfp  -Os -MD -std=c99 -c 

#LINKER FLAGS
LDFLAGS =  -T $(LD_SCRIPT) -e Reset_Handler



# Rules to build bin
all: bin/$(PROJECT).bin

$(OBJ)%.o: src/%.c               #turns .c source files into object files
    $(MKDIR)              
    $(CC) -o $@ $^ $(INC) $(CFLAGS)

$(OBJ)%.o: libs/%.c                #turns .c source files into object files
    $(MKDIR)              
    $(CC) -o $@ $^ $(INC) $(CFLAGS)
    

bin/$(PROJECT).elf: $(OBJS)    ##contains debug symbols for GNU GDB
    $(MKDIR)              
    $(LD)   -o $@ $^  $(LDFLAGS) 






bin/$(PROJECT).bin: bin/$(PROJECT).elf    #debug symbols for GNU GDB stripped by objcopy,finished binary ready for flashing
    $(OBJCOPY) -O binary $< $@


#Flashes bin to TM4C
flash:
    $(FLASHER) -S $(DEV) bin/$(PROJECT).bin

#remove object and bin files
clean:
    -$(RM) obj
    -$(RM) bin

.PHONY: all clean

errors:

arm-none-eabi-gcc  -o obj/ntc_sensor.o libs/ntc_sensor.c -Iinc -I/usr/lib/arm-none-eabi/include -ggdb -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16  -mfloat-abi=softfp  -Os -MD -std=c99 -c 
arm-none-eabi-ld    -o bin/main.user obj/main.o obj/gd32f30x_rcu.o obj/gd32f30x_gpio.o obj/ntc_sensor.o obj/HT1621B.o obj/temp_ctrl.o obj/gd32f30x_it.o obj/systick.o obj/gd32f30x_pmu.o obj/system_gd32f30x.o obj/startup.o obj/gd32f30x_adc.o  -T ld/GD32f30x.ld -e Reset_Handler 
arm-none-eabi-ld: obj/ntc_sensor.o: in function `ln':
/home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:51: undefined reference to `__aeabi_dsub'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:51: undefined reference to `__aeabi_dadd'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:51: undefined reference to `__aeabi_ddiv'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:56: undefined reference to `__aeabi_dcmpgt'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:64: undefined reference to `__aeabi_dadd'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:58: undefined reference to `__aeabi_dadd'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:60: undefined reference to `__aeabi_dadd'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:61: undefined reference to `__aeabi_dmul'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:61: undefined reference to `__aeabi_dmul'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:62: undefined reference to `__aeabi_ddiv'
arm-none-eabi-ld: obj/ntc_sensor.o: in function `log10':
/home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:70: undefined reference to `__aeabi_dmul'
arm-none-eabi-ld: obj/ntc_sensor.o: in function `get_ntc_Temperature':
/home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:121: undefined reference to `__aeabi_f2d'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:121: undefined reference to `__aeabi_dmul'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:121: undefined reference to `__aeabi_dadd'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:121: undefined reference to `__aeabi_d2f'
make: *** [Makefile:51: bin/main.user] Error 1
user@user-PC:~/project/embedded/ARM/GigaDevice/GD32f30x/Termostat$ make
arm-none-eabi-ld    -o bin/main.user obj/main.o obj/gd32f30x_rcu.o obj/gd32f30x_gpio.o obj/ntc_sensor.o obj/HT1621B.o obj/temp_ctrl.o obj/gd32f30x_it.o obj/systick.o obj/gd32f30x_pmu.o obj/system_gd32f30x.o obj/startup.o obj/gd32f30x_adc.o  -T ld/GD32f30x.ld -e Reset_Handler 
arm-none-eabi-ld: obj/ntc_sensor.o: in function `ln':
/home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:51: undefined reference to `__aeabi_dsub'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:51: undefined reference to `__aeabi_dadd'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:51: undefined reference to `__aeabi_ddiv'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:56: undefined reference to `__aeabi_dcmpgt'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:64: undefined reference to `__aeabi_dadd'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:58: undefined reference to `__aeabi_dadd'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:60: undefined reference to `__aeabi_dadd'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:61: undefined reference to `__aeabi_dmul'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:61: undefined reference to `__aeabi_dmul'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:62: undefined reference to `__aeabi_ddiv'
arm-none-eabi-ld: obj/ntc_sensor.o: in function `log10':
/home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:70: undefined reference to `__aeabi_dmul'
arm-none-eabi-ld: obj/ntc_sensor.o: in function `get_ntc_Temperature':
/home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:121: undefined reference to `__aeabi_f2d'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:121: undefined reference to `__aeabi_dmul'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:121: undefined reference to `__aeabi_dadd'
arm-none-eabi-ld: /home/user/project/embedded/ARM/GigaDevice/GD32f30x/Termostat/libs/ntc_sensor.c:121: undefined reference to `__aeabi_d2f'
make: *** [Makefile:51: bin/main.user] Error 1
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – John Bollinger Jan 16 '23 at 14:10
  • Probably you need to add the math library to your link line via `-lm`. – MadScientist Jan 16 '23 at 14:30
  • with an apt-gotten toolchain (and/or perhaps others) adding -lm and possibly using gcc to call the linker does work with log10f() I tested it. End of the day the library comes from your C library arm-none-eabi has little to do with it since gcc and binutils are compiler and binary tools not a C library. – old_timer Jan 17 '23 at 04:32
  • ahh you say on ubuntu so yes if this is the apt-gotten toolchain just add the -lm. as mentioned above – old_timer Jan 17 '23 at 04:33
  • Thank you for your answers. i added -lm to cF lag but nothing be changed and if i add -lm to LF lag says "cannot find -lm" – mohsen setodeh Jan 26 '23 at 13:24

0 Answers0