LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 10-06-2009, 02:26 AM   #1
kvijaik
LQ Newbie
 
Registered: Sep 2009
Posts: 9

Rep: Reputation: 0
collect2: ld returned 1 exit status


#include <stdio.h>
#include <math.h>
main()
{
float x, y, z, d = 0;
printf("Please enter value for x:\n");
scanf("%f", &x);
printf("Please enter value for y:\n");
scanf("%f", &y);
printf("Please enter value for z:\n");
scanf("%f", &z);
d = sqrt((x*x) + (y*y) + (z*z));
printf("The distance to your point was %f\n", d);
}

-bash-3.2# vi pythogoros.c
-bash-3.2# cc -o pythogoros pythogoros.c
/tmp/cc31sDdi.o: In function `main':
pythogoros.c.text+0xb0): undefined reference to `sqrt'
collect2: ld returned 1 exit status

I have typed the above program in vi editor and saved and compiled as mentioned above i am getting error message:
/tmp/cc31sDdi.o: In function `main':
pythogoros.c.text+0xb0): undefined reference to `sqrt'
collect2: ld returned 1 exit status

will somebody help me on this. I am running the Fedora 10 OS.
 
Old 10-06-2009, 03:48 AM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by kvijaik View Post
#include <stdio.h>
#include <math.h>
main()
{
float x, y, z, d = 0;
printf("Please enter value for x:\n");
scanf("%f", &x);
printf("Please enter value for y:\n");
scanf("%f", &y);
printf("Please enter value for z:\n");
scanf("%f", &z);
d = sqrt((x*x) + (y*y) + (z*z));
printf("The distance to your point was %f\n", d);
}

-bash-3.2# vi pythogoros.c
-bash-3.2# cc -o pythogoros pythogoros.c
/tmp/cc31sDdi.o: In function `main':
pythogoros.c.text+0xb0): undefined reference to `sqrt'
collect2: ld returned 1 exit status

I have typed the above program in vi editor and saved and compiled as mentioned above i am getting error message:
/tmp/cc31sDdi.o: In function `main':
pythogoros.c.text+0xb0): undefined reference to `sqrt'
collect2: ld returned 1 exit status

will somebody help me on this. I am running the Fedora 10 OS.
You are invoking the compiler incorrectly. Try this:

Code:
$ g++ pythogoros.c -o pythogoros
Also, you need to start indenting your source code.

And ... are you obliged to use C? A C++ version of this same program would be much more robust and understandable. And it wouldn't need to use the risky and unreliable scanf() function.

Finally, there are much better editors than vi. Using vi is going to hurt your productivity.
 
Old 10-07-2009, 09:17 PM   #3
kvijaik
LQ Newbie
 
Registered: Sep 2009
Posts: 9

Original Poster
Rep: Reputation: 0
Hi Paul,

Thanks for the help it worked for me.

I am a learner of C language on linux, quick question why the code was not getting compiled with the cc and gcc. If i want to compile the code with cc what will be my command.

Thanks,
Vijai.K
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
collect2: ld returned 1 exit status Ritendra Linux - Newbie 2 07-30-2009 07:39 AM
ld: cannot find -lc collect2: ld returned 1 exit status ArbuZz Linux From Scratch 3 09-27-2005 12:52 AM
collect2: ld returned 1 exit status abirami Linux - Software 0 03-02-2005 01:07 AM
konstruct error collect2: ld returned 1 exit status X2O Linux - Software 2 08-11-2004 08:48 PM
popa3d collect2: ld returned 1 exit status datapunk Linux - Software 1 01-02-2004 06:48 PM


All times are GMT -5. The time now is 11:59 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration