Results 1 to 4 of 4
I have Ubuntu Linux. I have just writen programm in C by Eclipse C++ but it does not work in Linux. And it works in Windows.
Code:
#include <stdio.h>
#include ...
- 11-03-2010 #1Just Joined!
- Join Date
- Nov 2010
- Posts
- 7
C Problems in linux, In Eclipse C
I have Ubuntu Linux. I have just writen programm in C by Eclipse C++ but it does not work in Linux. And it works in Windows.
There is error:Code:#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { float a,b; a=49; b= sqrt(a); printf("%f", b); }
Code:make all Building target: Program_Name Invoking: GCC C Linker gcc -o"Program_Nam" ./src/Program_Nam.o ./src/Program_Nam.o: In function `main': /home/koro/Documents/C/Program_Nam/Debug/../src/Program_Nam.c:17: undefined reference to `sqrt' collect2: ld returned 1 exit status make: *** [Program_Nam] Error 1
I also make the same in Windows Dev C++ and there works. Linux have probblems with this code: b= sqrt(a);
do you Know why and what can I do?
Also I can run this proggram with terminal by gcc. For example:
if I add "-lm" to this code program will work. For exaple:Code:gcc code.c -o code ./code
I wont to know why is imposible to run the program without -lm? why is -lm important? what is -lm and -o?Code:gcc code.c -o code -lm
And how can I run the program in Eclipse C++ in linux. Because Eclipse is more comfortable than Terminal and notepad. it's comportable like Dev C++.Last edited by vakhoQ; 11-03-2010 at 07:25 PM.
- 11-03-2010 #2
Using the -lm switch tells the compiler to include the math library.
Make mine Arch Linux
- 11-04-2010 #3Just Joined!
- Join Date
- Nov 2010
- Posts
- 7
-o, -lm, math.h n' Eclipse C++
1) And what is -o? why can't link my program to the math library? I have writen in the code #include <math.h>
2) And how can I compile my program in Eclipse C++? The program automaticly debugs my code. I dont use Termingal here.
Thanks a lot
- 11-04-2010 #4
The -o switch tells the compiler that the following name is the name of the executable...
Including <math.h> is just pasting the contents of the math.h header file into the said file. Using the -lm informs the compiler to use the math 'library' for name/label resolution..
Question two? I never used Eclipse C++ so I don't know...Make mine Arch Linux


Reply With Quote
