Like Tree1Likes
  • 1 Post By Salem

GCC compiling with <math.h>

This is a discussion on GCC compiling with <math.h> within the C Programming forums, part of the General Programming Boards category; I have a unique problem here, well not actually a problem. Just something I am trying to understand. I have ...

  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 10:50 AM.

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

  3. #3
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    I just tested, and it seems than the math library is now linked by default.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    Compile with -fno-builtin and see what happens.
    GReaper likes this.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02: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, 07:15 PM

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