LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-22-2006, 07:50 AM   #1
lgi123
LQ Newbie
 
Registered: Jun 2006
Posts: 4

Rep: Reputation: 0
Standard function problems with gcc


I have problems using standard functions like floor() and ceil() with gcc.

For example, I get: /tmp/ccMNi7Hj.o: In function `main':floor.c.text+0x21): undefined reference to `floor'
collect2: ld returned 1 exit status

when trying to build this:

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

int main(void)
{
        double d = 12.3;
        d = floor(d);
        printf("%f\n", d);

        return 0;
}
However, this works fine:

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

int main(void)
{
        printf("%f\n", floor(12.3));

        return 0;
}
But I have no problems with any of this when using Dev-C++ under Windows XP. Does something have to be done differently with gcc under Linux or do I have a bad configuration/libraries?

Last edited by lgi123; 06-22-2006 at 08:07 AM.
 
Old 06-22-2006, 08:13 AM   #2
Flesym
Member
 
Registered: Aug 2005
Location: Germany
Distribution: Ubuntu, Debian
Posts: 189

Rep: Reputation: 31
You have to link against libm.a Thus compile with:
Code:
gcc filename -lm
 
Old 06-23-2006, 03:17 PM   #3
lgi123
LQ Newbie
 
Registered: Jun 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Flesym
You have to link against libm.a Thus compile with:
Code:
gcc filename -lm
Thanks, Now it works!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gcc: recursive function quirk Disruptor Linux - Software 4 09-23-2014 05:45 AM
compilation error in standard header fpos.h in gcc 3.2.2 ghorab Linux - General 6 12-10-2005 03:26 AM
error in gcc / g++ standard file maheshbmane Programming 6 09-02-2005 08:30 PM
Use gcc and standard libraries with SUSE 9.1 Personal warrenpatrick Linux - Newbie 3 10-10-2004 07:26 PM
GCC doesn't find the Standard-Library the_styler Linux - Software 11 01-15-2004 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration