Forum: ARM programming with GCC/GNU tools math.h problem - once again

Author: Rafal Urbaniak (wujo)
Posted on:

Rate this post
0 useful
not useful
Hello evryone!

First of whole sorry for my english.

I am building a system with AT91SAM7X128 microcontroller. While writing
code I base on gettin-started-project downloaded from Atmel site. I
compile my project with WinArm 20060606 version.
I need to use floating point numbers and some mathematics functions, but
I have problem with math.h library. I.e. if i try to use sin() function
i get
the error:
tarted-project/main.c:335: undefined reference to `sin'

during linking project.

Ofcourse I included math.h library

Here is makefile from my project:


#    Makefile for compiling the Getting Started project

#      User-modifiable options

# Chip & board used for compilation
# (can be overriden by adding CHIP=chip and BOARD=board to the
CHIP  = at91sam7x128
BOARD = at91sam7x-ek

# Optimization level, put in comment for debugging

# AT91 library directory
AT91LIB = ../at91lib

# Output file basename
OUTPUT = main

# Output directories
BIN = bin
OBJ = obj

#      Tools

# Tool suffix when cross-compiling
CROSS = arm-elf-

# Compilation tools
CC = $(CROSS)gcc
SIZE = $(CROSS)size
STRIP = $(CROSS)strip
OBJCOPY = $(CROSS)objcopy

# Flags
INCLUDES = -I$(AT91LIB)/boards/$(BOARD) -I$(AT91LIB)/peripherals
INCLUDES += -I$(AT91LIB)/components -I$(AT91LIB)/utility -I$(AT91LIB)

CFLAGS = -mlong-calls -ffunction-sections -Wall
LDFLAGS = -g $(OPTIMIZATION) -nostdlib -Wl,--gc-sections -lm -lc -lgcc

#      Files

# Directories where source files can be found
UTILITY = $(AT91LIB)/utility
PERIPH = $(AT91LIB)/peripherals
BOARDS = $(AT91LIB)/boards

VPATH += $(PERIPH)/dbgu $(PERIPH)/aic $(PERIPH)/pio $(PERIPH)/pit

# Objects built from C source files
C_OBJECTS = main.o
C_OBJECTS += led.o pa.o latch.o buff.o count.o mem.o usart.o system.o
dig_pot.o clkgen.o div0.o
C_OBJECTS += dbgu.o pio.o aic.o pio_it.o pit.o
C_OBJECTS += board_memories.o board_lowlevel.o

# Objects built from Assembly source files
ASM_OBJECTS = board_cstartup.o _udivsi3.o

# Append output directories to files
C_OBJECTS := $(addprefix $(OBJ)/, $(C_OBJECTS))
ASM_OBJECTS := $(addprefix $(OBJ)/, $(ASM_OBJECTS))
OUTPUT := $(addprefix $(BIN)/, $(OUTPUT))

#      Rules

# Get the list of available targets from the board.mak file
include $(AT91LIB)/boards/$(BOARD)/board.mak

all: $(BIN) $(MEMORIES)

$(BIN) $(OBJ):
   mkdir $@

   $(CC) $(LDFLAGS) -T"$(AT91LIB)/boards/$(BOARD)/$(CHIP)/$@.lds" -o
$(OUTPUT)-$@.elf $^
   $(OBJCOPY) -O binary $(OUTPUT)-$@.elf $(OUTPUT)-$@.bin

$(C_OBJECTS): $(OBJ)/%.o: %.c $(OBJ) Makefile
   $(CC) $(CFLAGS) -c -o $@ $<

$(ASM_OBJECTS): $(OBJ)/%.o: %.S $(OBJ) Makefile
   $(CC) $(ASFLAGS) -c -o $@ $<

   rm -f $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf

I suppose the problem is in makefile. I found an information that I
should add libm.a libg.a and libgcc.a to linker files.
I tried to add -lm -lg and -lgcc flags to LFLAGS but it didn't work.

What should I change in makefile to use math functions from math.h?
I'm not familiar with construction of makefiles, and I have not idea
where is the problem.

I would be grateful for any answer.

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Please create a minimal example with startup-code, linker-script,
makefile and a simple application-code to reproduce the issue, pack it
and attach it to a forum-message.


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.