Thread: GCC compiling with <math.h>

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    111

    GCC compiling with <math.h>

    I have a unique problem here, well not actually a problem. Just something I am trying to understand.

    I have a program that uses math.h and I am using pow().

    I found that when I use GCC to compile (under a unix environment), I am able to do so without the -lm command, while some of my classmates are required to do so. As in, gcc -lm <programName> or gcc <programName> -lm.

    My GCC is not under an, alias. And I don't know what else to supply as information, if you need more with commands to run, just ask.

    I'm just trying to figure out why I do not need -lm while other folks do. Besides the different routes we used to get to the same problem, we solved that problem the same way, in using pow().

    I understand that there may not be a true answer, as to why, but I'm just looking to some insight or options to look into.

    Thank You
    Last edited by Strahd; 02-20-2012 at 11:50 AM.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Are you by any chance using the "-c" option?...
    Devoted my life to programming...

  3. #3
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    I just tested, and it seems than the math library is now linked by default.

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    111
    Quote Originally Posted by GReaper View Post
    Are you by any chance using the "-c" option?...
    I am not, just regular gcc <fileName.c>

  5. #5
    Registered User
    Join Date
    Sep 2011
    Posts
    111
    Quote Originally Posted by manasij7479 View Post
    I just tested, and it seems than the math library is now linked by default.
    Ahh ok that would make more sense then. A matter of GCC version numbers, lol.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Compile with -fno-builtin and see what happens.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Math
    By knightjp in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 04-01-2009, 05:36 PM
  2. there is (ln) in the math.h
    By elton_fan in forum C Programming
    Replies: 6
    Last Post: 03-24-2007, 02:46 PM
  3. Basic Math Problem. Undefined Math Functions
    By gsoft in forum C Programming
    Replies: 1
    Last Post: 12-28-2004, 03:14 AM
  4. Math Help
    By CAP in forum C Programming
    Replies: 2
    Last Post: 08-19-2002, 12:03 AM
  5. Math?
    By Kavity in forum C++ Programming
    Replies: 6
    Last Post: 02-26-2002, 08:15 PM