problem with gcc compiler and math functions

Using applications, configuring, problems
Post Reply
Message
Author
gemera
Posts: 14
Joined: Fri 17 Feb 2012, 19:19

problem with gcc compiler and math functions

#1 Post by gemera »

I've compiled tons of c programs in Puppy using Geany and the gcc compiler without any problems.

But for the first time I have used one of the math functions defined in the <math.h> header and get an error which I just can't solve.

Since I am learning c for both Windows and Linux I know the program works in the gcc compiler in Codeblocks for Windows.

Code: Select all


#include <math.h>
#include <stdio.h>

int main(void)
{
      double x,y;

      x = 5;

      y = sqrt(x);

      return 0;
}

the error message is

Code: Select all


/tmp/ccr0Yo3k.o: In function `main':
/root/test.c:11:undefined reference to `sqrt'
collect2: ld returned 1 exit status
make: ***[all] Error 1

btw I can use ANY of the math functions and get the same error.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#2 Post by SFR »

Hey Gemera

Although I don't know C at all (high time to learn it at last...), but I think this will shed some light on the problem:
https://bbs.archlinux.org/viewtopic.php?id=47461

I've compiled your example with -lm and it seems to be ok...

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

gemera
Posts: 14
Joined: Fri 17 Feb 2012, 19:19

#3 Post by gemera »

thanks for the heads up sdk.

really appreciated!

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#4 Post by Karl Godt »

This is with newer gcc i think . Had similar on Puppy Precise .
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

Post Reply