gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Very Stupid Question: Which Library Implements sin()?

#8319 - dchartier - Tue Jul 08, 2003 5:34 am

The title says it all: My linker can't find the implementations for sin() and cos(). I run gcc with the parameters:

gcc sketch.c sketch.elf -I <include-dir>

I've installed the DevKit Advance from http://devkitadv.sourceforge.net/download.html with the following modules:

- core
- binutils
- gcc
- newlib

Under devkitadv\lib\gcc-lib\arm-agb-elf\3.0.2, I find libgcc.a, but an "nm" on this file finds neither sin() nor cos(). The only place I could find such implementations was in devkitadv\arm-agb-elf\lib\libm.a, but I can't get gcc to link to this library. I figure that I must be doing something wrong.

Can anyone tell me what I need to do to get this project to link?

Thanks!

#8320 - tepples - Tue Jul 08, 2003 5:59 am

It'd be most efficient to write your own cos() and sin() based on lookup tables, but if you really want to use the dog-slow built-in version in libm.a:
  1. #include <math.h>
  2. link with -lm

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#8321 - dchartier - Tue Jul 08, 2003 6:03 am

[quote="tepples"]It'd be most efficient to write your own cos() and sin() based on lookup tables, but if you really want to use the dog-slow built-in version in libm.a:
[list=1][*]#include <math.h>[*]link with -lm[/list][/quote]

Thank you!

Actually, I was using the standard trig functions to generate in-memory sine and cosine look-up tables at program start-up. But your advice is well taken.

#8348 - Archeious - Tue Jul 08, 2003 9:44 pm

dchartier wrote:
tepples wrote:
It'd be most efficient to write your own cos() and sin() based on lookup tables, but if you really want to use the dog-slow built-in version in libm.a:
  1. #include <math.h>
  2. link with -lm


Thank you!

Actually, I was using the standard trig functions to generate in-memory sine and cosine look-up tables at program start-up. But your advice is well taken.


I would suggest pregenerating this on your PC as a .h file and include that in your project. Just a thought, they are few and far between so I thought I would share it. :)

#8442 - dchartier - Thu Jul 10, 2003 8:28 pm

Archeious wrote:
dchartier wrote:
tepples wrote:
It'd be most efficient to write your own cos() and sin() based on lookup tables, but if you really want to use the dog-slow built-in version in libm.a:
  1. #include <math.h>
  2. link with -lm


Thank you!

Actually, I was using the standard trig functions to generate in-memory sine and cosine look-up tables at program start-up. But your advice is well taken.


I would suggest pregenerating this on your PC as a .h file and include that in your project. Just a thought, they are few and far between so I thought I would share it. :)


Good point: I noticed that invoking the trigonometic functions 720 times was agonizingly slow!