0

I have a problem much like the one here where the error is "Undefined reference to sqrt". I understand how using the -lm flag when compiling fixes the problem by linking it to the math library, however, are there any other possible ways to fix the problem without using any special compiler flags?

I've been happily using "-lm" while compiling my project so far, but my instructor uses try which won't accept a submission unless it compiles.... they do not use -lm.

Is there a way to solve this that doesn't require me to write my own square root function?

Community
  • 1
  • 1
mdw7326
  • 163
  • 1
  • 1
  • 9
  • Not really; either you link against an existing library (the standard `libm` in this case), or you roll your own implementation, or you find the source code for an implementation and copy-and-paste it. – Oliver Charlesworth Feb 23 '14 at 19:54
  • If your instructor compiles without `-lm`, then you probably shouldn't be using it. – Filipe Gonçalves Feb 23 '14 at 19:55
  • 5
    E-mail your professor? Unless you're not supposed to be using `sqrt` for some reason. –  Feb 23 '14 at 19:58
  • P.S. I needed square root for the distance formula, so that I could find the area of a triangle. Dot Product hadn't occurred to me at the time. – mdw7326 Feb 23 '14 at 21:34

1 Answers1

4

Other than making your own sqrt method no, though some compilers have the sqrt function already in them from what I've used so you may not need the extra flag potentially. I would email your instructor and talk to him about this.

GEMISIS
  • 434
  • 3
  • 11
  • 1
    There's always the possibility that the compiler they're using is crap. The professor that is, not the student. –  Feb 23 '14 at 20:00
  • Okay, thank you. I didn't think there was another way, but also couldn't find anything on the internet saying there wasn't. – mdw7326 Feb 23 '14 at 20:05