Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[SOLVED]noob: can't access math function

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
arca
Posts: 2
Joined: 2015-04-30 15:48

[SOLVED]noob: can't access math function

#1 Post by arca »

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.

User avatar
aicardi
Posts: 388
Joined: 2009-11-18 01:30
Location: Chicago

Re: noob: can't access math function

#2 Post by aicardi »

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

arca
Posts: 2
Joined: 2015-04-30 15:48

Re: noob: can't access math function

#3 Post by arca »

It works with the -lm option! Great.
Thank you very much, it was really frustrating.

Post Reply