![]() |
|
#1
|
|||
|
|||
The sqrt functionHello all, everyone's favorite n00b is back with more n0obish questions! This one is actually quite simple, I promise. In short, my C textbook claims that the function "sqrt" is contained within the library math.h so I included it along with stdio.h and stdlib.h in my code. However, whenever I try to use the sqrt function in my code I frequently get the message:
"/tmp/ccG8aDU0.o(.text+0x3d3): In function `GetLen1': : undefined reference to `sqrt' collect2: ld returned 1 exit status" ~Note: GetLen1 is the function containing my sqrt line~ Is there something else I am supposed to do before I can use the sqrt command? |
|
#2
|
|||
|
|||
Re: The sqrt functionSounds like you need to link with the library containing sqrt (namely math.lib or libmath.a).
|
|
#3
|
|||
|
|||
Re: The sqrt functionI have the line:
"#include <math.h>" in my code already, specifically how would I write an introduction for those others you have suggested? Would it simply be: "#include <math.lib>" ? |
|
#4
|
|||
|
|||
Re: The sqrt functionNo, it's going to be some option in your compiler. I would guess from the error that you're using GCC, but do you use the command line or some IDE? On the command line it would be adding an argument to the gcc execution, in an IDE it would depend on the IDE.
|
|
#5
|
|||
|
|||
Re: The sqrt functionI am sorry but I do not understand. When I compile I type:
"cc filename" into the command line. I don't really know which compiler that is as I am new to the system, but that is it. Do you know how I can debug this program and make it recognize the sqrt function? |
|
#6
|
|||
|
|||
Re: The sqrt functionQuote:
The command line to link in the math library is: Code:
The "-lm" is an idiom, telling the compiler to pass information to the linker to use libm.a (the math library). I would use something like Code:
This lets the compiler give you all of the warnings that it thinks are appropriate for common errors that people make that aren't actually violations of the language but are likely to be mistakes. Regards, Dave |
Recent GIDBlog
Toyota - 2008 August Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 13:12 |
| [Tutorial] Function Pointers | aaroncohn | C++ Forum | 4 | 17-Feb-2006 11:33 |
| [GIM] gim.h | dsmith | C Programming Language | 0 | 18-Jan-2005 08:48 |
| Nested for loop with function | Tori | C++ Forum | 11 | 08-Nov-2004 13:02 |
| Revising Script style ?????? | pepee | MySQL / PHP Forum | 4 | 14-Apr-2004 04:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The