gcc and math.h

This is a discussion on gcc and math.h within the C Programming forums, part of the General Programming Boards category; i wrote a program that is supposed to print the sin, cos and sqrt of some float. i include math.h. ...

  1. #1
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246

    gcc and math.h

    i wrote a program that is supposed to print the sin, cos and sqrt of some float. i include math.h. but when i try to compile i get
    Code:
    tmp/cc2oPQ8z.o(.text+0x1ad): In function `main':
    : undefined reference to `cos'
    /tmp/cc2oPQ8z.o(.text+0x1e3): In function `main':
    : undefined reference to `sin'
    /tmp/cc2oPQ8z.o(.text+0x21c): In function `main':
    : undefined reference to `sqrt'
    /tmp/cc2oPQ8z.o(.text+0x231): In function
    why doesnt it find those functions?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Maybe?
    gcc -Wall -lm filename.c

  3. #3
    twm
    twm is offline
    root
    Join Date
    Sep 2003
    Posts
    232
    >gcc -Wall -lm filename.c
    Maybe not.
    Code:
    gcc -Wall filename.c -lm
    There, that's better.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  4. #4
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    thanks a lot , it works now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. math.h
    By tsutharssan in forum C Programming
    Replies: 3
    Last Post: 07-03-2009, 02:24 PM
  2. undefined reference to `sqrt' when using math.h
    By Milhas in forum C Programming
    Replies: 4
    Last Post: 03-31-2008, 06:11 PM
  3. Including math.h doesn't seem to work?
    By scorpion_gr in forum C Programming
    Replies: 5
    Last Post: 08-07-2007, 09:34 AM
  4. weird errors gcc : functions like floor(), ceil(), sqrt()
    By gemini_shooter in forum C Programming
    Replies: 2
    Last Post: 06-04-2005, 09:00 AM
  5. weird errors gcc: functions like floor(), ceil(), sqrt()
    By gemini_shooter in forum Linux Programming
    Replies: 2
    Last Post: 06-04-2005, 08:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21