Math.h - how to use! Help!

All design tool related questions: compiler, assembler, linker. Embedded programming questions: assembler, C code.

Moderator: nferre

Posts: 1
Joined: Fri Oct 19, 2007 11:49 am

Math.h - how to use! Help!

Fri Jan 18, 2008 5:26 pm

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 errors:
tarted-project/main.c:335: undefined reference to `sin'
tarted-project/main.c:335: undefined reference to `__truncdfsf2'

during linking project.

Ofcourse I included math.h library

Here is makefile from my project:

Code: Select all

# ---------------------------------------------------------------------------- 

# 	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

# 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

#		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)/$" -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
# **********************************************************************************************
#                            FLASH PROGRAMMING                                         
# Alternate make target for flash programming only
# You must create a special Eclipse make target (program) to run this part of the makefile 
# (Project -> Create Make Target...  then set the Target Name and Make Target to "program")
# OpenOCD is run in "batch" mode with a special configuration file and a script file containing
# the flash commands. When flash programming completes, OpenOCD terminates.
# Note that the script file of flash commands (script.ocd) is part of the project
# Programmers: Martin Thomas, Joseph M Dupre, James P Lynch
# **********************************************************************************************
# specify output filename here (must be *.bin file)
TARGET = c:\main-flash.bin

# specify the directory where openocd executable and configuration files reside (note: use forward slashes /)
OPENOCD_DIR = 'c:/Program Files/openocd-2007re204/bin/'

# specify OpenOCD executable (pp is for the wiggler, ftd2xx is for the USB debuggers)
OPENOCD = $(OPENOCD_DIR)openocd-pp.exe
#OPENOCD = $(OPENOCD_DIR)openocd-ftd2xx.exe

# specify OpenOCD configuration file (pick the one for your device)
OPENOCD_CFG = $(OPENOCD_DIR)at91sam7s256-wiggler-flash-program.cfg
#OPENOCD_CFG = $(OPENOCD_DIR)at91sam7s256-jtagkey-flash-program.cfg
#OPENOCD_CFG = $(OPENOCD_DIR)at91sam7s256-armusbocd-flash-program.cfg

# program the AT91SAM7S256 internal flash memory
program: $(TARGET)
	@echo "Flash Programming with OpenOCD..."			# display a message on the console
	$(OPENOCD) -f $(OPENOCD_CFG)						# program the onchip FLASH here
	@echo "Flash Programming Finished."					# display a message on the console
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, but I don't know how!
I tried to use -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 would be grateful for any answer.
Location: Poland
Posts: 10
Joined: Wed Jan 30, 2008 6:53 pm

Re: Math.h - how to use! Help!

Wed Feb 25, 2009 10:34 pm

Have you solve your problem? I've got the same :(

Return to “Development Tools”

Who is online

Users browsing this forum: No registered users and 4 guests