math.h problem - once again

OP #1173495
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:
D:\ARM_program\getting-started-project-1.0-at91sam7x-ek\getting-s
tarted-project/main.c:335: undefined reference to `sin'

during linking project.

Ofcourse I included math.h library

Here is makefile from my project:

Code:
#
------------------------------------------------------------------------ 
----

#    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
command-line)
CHIP  = at91sam7x128
BOARD = at91sam7x-ek

# Optimization level, put in comment for debugging
#OPTIMIZATION = -Os

# 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
CFLAGS += -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP)  #-DNOTRACE
ASFLAGS = -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
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 += $(UTILITY)
VPATH += $(PERIPH)/dbgu $(PERIPH)/aic $(PERIPH)/pio $(PERIPH)/pit
VPATH += $(BOARDS)/$(BOARD) $(BOARDS)/$(BOARD)/$(CHIP)

# 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 $@

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

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

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

clean:
   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.

Reply

A question of your own? This thread is over 18 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.