June 27, 2007

Error in Linux programming, undefined refrence to 'pow'?

I wrote a c program in linux :

  1. #include <math.h>
  2. {
  3. for(I=0;I<=l;I++)
  4. k=k+((int) str[m-I]-48)*(int) pow(10,I);
  5. Why this error occured?
  6. but when compile with gcc promt me:
  7. }
  8. you may need to compile with the -lm compiler directive….

    so compile like this

    gcc source.c -lm

  9. :undefined refrence to 'pow'
  10. int m,I,,k=0;
  11. I prefer the method below for converting strings to ints in C++,
    what I can see from your code is an un-declared array (char str[]) and from my research it looks like your missing the following header file: #include <sstream>

    my way:
    #include <sstream>
    #include <string>
    using namespace std;

    // string to int
    string some_string;
    istringstream buffer(some_string);
    int some_int;
    buffer >> some_int;

    // int to string
    int some_int;
    ostringstream buffer;
    buffer << some_int;
    string some_string = buffer.str();

  12. return(k);
  13. /tmp/cciDKLpD.o(.txt+0×57): In function 'str2int' :
  14. int str2int(char str[])
  15. #include <string.h>
  16. collected2: ld returned 1 exit status.
  17. m=strlen(str)-1;

Tags: ,

Tell a Friend Today!

del.icio.us Digg Furl Reddit Ask BlinkList blogmarks Blogg-Buzz Google Ma.gnolia Netscape ppnow Rojo Shadows Simpy Socializer Spurl StumbleUpon Tailrank Technorati Windows Live Wists Yahoo! Help

Permalink • Print

Track this entry

RSS BlogPulse

RSS Technorati Cosmos

Related Searches

, , , ,