I am trying to write a quick program in C that uses sin/cos. But all the variables I use are ints (whereas sin/cos need floats). So KermM gave me some code to try for that: (int)sin((float)myinteger)

But, I think something is up because I get this error(s):

$ make
nspire-gcc -Os -Wall -W -fpic -fno-merge-constants -D NON_CAS -c main.c
main.c: In function 'main':
main.c:64:3: warning: implicit declaration of function 'cos'
main.c:64:13: warning: incompatible implicit declaration of built-in function 'cos'
main.c:65:3: warning: implicit declaration of function 'sin'
main.c:65:13: warning: incompatible implicit declaration of built-in function 'sin'
nspire-ld main.o utils.o graphics3.o -o Trapped.elf
main.o: In function `main':
main.c:(.text+0xd8): undefined reference to `cos'
main.c:(.text+0x278): undefined reference to `cos'
main.c:(.text+0x2a4): undefined reference to `sin'
main.c:(.text+0x330): undefined reference to `cos'
main.c:(.text+0x358): undefined reference to `sin'
collect2: ld returned 1 exit status
make: *** [Trapped.tns] Error 1




On this line: y += (int)sin((float)direction) * y_speed;


Any help please :)
Try adding the -lm flag in your Makefile.

Edit: apparently there's no such thing as the standard libmath functions for the Nspire. Sad Try bwang's nmath file.
You'd usually need to #include <math.h> to use sin/cos in any case. See Kerm's answer for Nspire-specific details, though.
benryves wrote:
You'd usually need to #include <math.h> to use sin/cos in any case. See Kerm's answer for Nspire-specific details, though.
Aye, I was assuming that he had at least done that; maybe I shouldn't have made that assumption.
KermMartian wrote:
Aye, I was assuming that he had at least done that; maybe I shouldn't have made that assumption.


Quote:
main.c: In function 'main':
main.c:64:3: warning: implicit declaration of function 'cos'
main.c:64:13: warning: incompatible implicit declaration of built-in function 'cos'
main.c:65:3: warning: implicit declaration of function 'sin'
main.c:65:13: warning: incompatible implicit declaration of built-in function 'sin'


Nope, he forgot to include the header.

player1537, maybe you should start with an intro to C - you clearly have no idea how to program in C, or these errors would have been obvious in their meaning.
No, he is indeed a C newbie, but he's learning. Come on, we all had to start somewhere; even I was once baffled by pointers. Razz
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement