![]() |
| | #1 |
| & the hat of GPL slaying Join Date: Sep 2001
Posts: 5,732
| Compiling problem Error is: Code: /tmp/ccFbD8lA.o: In function `main': /tmp/ccFbD8lA.o(.text+0x9d): undefined reference to `sqrt' collect2: ld returned 1 exit status Code: #include <stdio.h>
#include <math.h>
int main()
{
int a, b, c, a2;
float x1, x2, part1;
printf("A: ");
scanf("%d", &a);
printf("B: ");
scanf("%d", &b);
printf("C: ");
scanf("%d", &c);
part1 = sqrt( (b*b) - 4*a*c);
a2 = 2*a;
printf("-b = %d\nB^2 - 4AC = %f\n2A = %d.\n", -b, part1, a2);
x1 = ((-b) + part1) / (2*a);
x2 = ((-b) - part1) / (2*a);
printf("X = %f\nX = %f", x1, x2);
return 0;
}
|
| Thantos is offline | |
| | #2 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,681
| gcc prog.c -lm That's lowercase LM |
| Salem is offline | |
| | #3 |
| & the hat of GPL slaying Join Date: Sep 2001
Posts: 5,732
| Ok it worked but what does the -lm do? I searched the man page for it and didn't even see that switch listed. Also it outputed the exe as a.out instead of prog.exe. Anyway to change this? BTW not used to command line compilers so bear with me please |
| Thantos is offline | |
| | #4 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,681
| The 'l' specifies that you want to include additional libraries (usually found in /usr/lib) The parameter -lxxx means you want to link a library called libxxx.a That is, the lib prefix and .a suffix are assumed. It's a feature of history that libm is separate from libc The companion -L option specifies where to look for libraries, in case you have your own. > Also it outputed the exe as a.out instead of prog.exe. gcc -o prog.exe prog.c -lm a.out, short for assember.out, being the traditional default name for the final result of compiling and linking a program. |
| Salem is offline | |
| | #5 |
| & the hat of GPL slaying Join Date: Sep 2001
Posts: 5,732
| Thanks Salem. I understand now. |
| Thantos is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem Running Program After Compiling | kristentx | C++ Programming | 13 | 09-12-2007 10:46 AM |
| Problem compiling simple code examples | Wintersun | Windows Programming | 8 | 08-14-2007 10:30 AM |
| A question related to strcmp | meili100 | C++ Programming | 6 | 07-07-2007 02:51 PM |
| compiling problem | tinkerbell20 | C++ Programming | 6 | 06-21-2005 12:12 PM |
| simple compiling problem | waxydock | C++ Programming | 2 | 03-26-2005 10:33 AM |