Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • Wow, when did that happen? stackoverflow.com/questions/1033898/… I'm pretty sure that was accurate a year ago… Commented Nov 30, 2010 at 21:49
  • @ephemient - libstdc++ still links to libm.so on my system (With G++ 4.4.5), but I meant that you shouldn't need the -lm flag to pull it in at all with C code. Commented Nov 30, 2010 at 21:54
  • I'm just wondering when that changed. Testing with GCC 4.2.4, 4.3.5, 4.4.3, 4.4.5, and 4.5.1, along with glibc 2.11.1 and 2.12.1, I still need -lm for plain gcc. Which modern GCC do you mean? Commented Nov 30, 2010 at 22:09
  • @ephemient - I'm using GCC 4.4.5 on Debian 5- it might just be a quirk with my version. I compiled C code using a bunch of the math.h functions, and compiled with just gcc source.c. I just tested on an RH5 machine with gcc 4.1.2 and it requires -lm. Time to edit my answer. Commented Nov 30, 2010 at 22:21
  • 1
    I wonder if it's architecture dependent. I've tested on 3 x86_64 machines: Gentoo, Debian sid (which comes with glibc 2.11.2, I miscounted in my earlier comment), Ubuntu Lucid. Also, are you sure you're actually linking the math functions? GCC's constant folding will fold the math functions too. Commented Nov 30, 2010 at 22:30