Jump to content

what's up with the math library?


Recommended Posts

I'm doing a very simple program including calls to cos and sqrt functions.

I get this when compiling:

/home/hippocampe/tmp/ccSzTSx5.o(.text+0x31): In function `main':

: undefined reference to `cos'

/home/hippocampe/tmp/ccSzTSx5.o(.text+0x4d): In function `main':

: undefined reference to `sqrt'

collect2: ld returned 1 exit status

 

Before you ask, I did include math.h :)

The program compiles but does not build in Anjuta.

It builds when I comment the lines containing these functions.

My system is Mandrake 9.1. I don't know if my system is missing any packages?

Thanks

 

PS: Somehow it works when I use g++ instead of gcc at the command line. Anjuta uses gcc so I get error messages when I build from there.

Anyone has an idea what is causing this? The file extension is .c

Link to comment
Share on other sites

Thanks guys, that definitely solved it.

I'm actually surprised I didn't come across this before....

So you actually need to explicitely link to the math library?

I'm surprised that it's not included by default when you include the corresponding header.

Why did it work with g++ without the -lm option?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...