[SOLVED]noob: can't access math function

Need help with C, C++, perl, python, etc?

[SOLVED]noob: can't access math function

Postby arca » 2015-04-30 16:14

Hi,
when i try to compile this code:

#include <math.h>

int main (void) {
double x, y;
x = 2;
y = sqrt(x);
return 0;
}

With the command:

$ gcc test.c

I got this message:

/tmp/cc5QZmCN.o: In function 'main':
test.c:(.text+0x16): undefined reference to 'sqrt'
collect2: error: ld returned 1 exit status

Any help?

I tried this on a fresh jessie install.
I have the same problem on wheezy.

Thanks in advance.
Last edited by arca on 2015-05-01 10:44, edited 1 time in total.
arca
 
Posts: 2
Joined: 2015-04-30 15:48

Re: noob: can't access math function

Postby aicardi » 2015-04-30 17:19

There's lots of stuff on this.
Here's one http://linux.die.net/man/3/sqrt

Code: Select all
gcc -o test test.c -lm


I do think you will want build-essential installed.
Jessie/Xfce
User avatar
aicardi
 
Posts: 388
Joined: 2009-11-18 01:30
Location: Chicago

Re: noob: can't access math function

Postby arca » 2015-05-01 10:31

It works with the -lm option! Great.
Thank you very much, it was really frustrating.
arca
 
Posts: 2
Joined: 2015-04-30 15:48


Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests

fashionable