June 27, 2007
Error in Linux programming, undefined refrence to 'pow'?
I wrote a c program in linux :
- #include <math.h>
- {
- for(I=0;I<=l;I++)
- k=k+((int) str[m-I]-48)*(int) pow(10,I);
- Why this error occured?
- but when compile with gcc promt me:
- }
- you may need to compile with the -lm compiler directive….
so compile like this
gcc source.c -lm
- :undefined refrence to 'pow'
- int m,I,,k=0;
- 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(); - return(k);
- /tmp/cciDKLpD.o(.txt+0×57): In function 'str2int' :
- int str2int(char str[])
- #include <string.h>
- collected2: ld returned 1 exit status.
- m=strlen(str)-1;
Tags: linux programming, embedded linux























