LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-06-2007, 11:40 PM   #1
hegdeshashi
Member
 
Registered: Dec 2005
Posts: 73
Blog Entries: 3

Rep: Reputation: 15
compiler problem???


Hi,

When I compiled my program,I am getting a strange error like..
============

gcc -o a a.c
---------------
a.c: In function ‘main’:
a.c:6: warning: incompatible implicit declaration of built-in function ‘printf’
/tmp/ccKpEN5H.o(.text+0x1b): In function `main':
: undefined reference to `sin'
collect2: ld returned 1 exit status
======================


can any one tell me solution...
 
Old 03-06-2007, 11:44 PM   #2
rocket357
Member
 
Registered: Mar 2007
Location: 127.0.0.1
Distribution: OpenBSD-CURRENT
Posts: 485
Blog Entries: 187

Rep: Reputation: 74
Well, given that error, it would appear you're trying to overload the "printf" function. You should rename the function that's causing the problem.
 
Old 03-06-2007, 11:56 PM   #3
hegdeshashi
Member
 
Registered: Dec 2005
Posts: 73

Original Poster
Blog Entries: 3

Rep: Reputation: 15
here is my program
==============
#include<math.h>
#include<stdio.h>
main()
{

printf("%d\n",sin(2));
}
===================

output
================
gcc -o a a.c


/tmp/ccJvnKLV.o(.text+0x1b): In function `main':
: undefined reference to `sin'
collect2: ld returned 1 exit status
=====================


now,what is the problem????
 
Old 03-07-2007, 12:01 AM   #4
rocket357
Member
 
Registered: Mar 2007
Location: 127.0.0.1
Distribution: OpenBSD-CURRENT
Posts: 485
Blog Entries: 187

Rep: Reputation: 74
You need to fully qualify sin(), I would think.
 
Old 03-07-2007, 12:12 AM   #5
hegdeshashi
Member
 
Registered: Dec 2005
Posts: 73

Original Poster
Blog Entries: 3

Rep: Reputation: 15
what do u mean...!!!!!!!!!!


My problem is on.....
collect2: ld returned 1 exit status

this,,,,
I mean .. linking problem..

I am having all header files ,but it is not able to link.
 
Old 03-07-2007, 04:29 PM   #6
PerpetualNewbie
Member
 
Registered: Dec 2006
Location: Kokomo and Muncie, IN
Distribution: Slackware 11.0
Posts: 36

Rep: Reputation: 16
Just after doing a quickie Google search, I'd suggest trying the two following things:
1) Instead of using "sin(2)", declare a variable (such as double x) and assign 2.0 to it, then use the variable in the sin function like this:
double x = 2.0;
...
printf("%d\n", sin(x));

2) Link the math library using the command -lm
So your compile command would look like this:
gcc a.c -o a -lm

I really hope this helps, I'm really kind of a n00b programmer Good luck!
 
Old 03-07-2007, 10:54 PM   #7
hegdeshashi
Member
 
Registered: Dec 2005
Posts: 73

Original Poster
Blog Entries: 3

Rep: Reputation: 15
Thx..PerpetualNewbie.

I got it...

Now ,one more problem,
When I run my shared memory programs,I am getting same linking error.

Is there any solution to overcome this linking?
 
  


Reply



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
checking for C compiler default output... configure: error: C compiler cannot create fiorejm Linux - Software 6 11-12-2009 12:35 PM
problem with compiler ale_x_andru Linux - Newbie 2 03-06-2006 12:21 AM
Compiler Problem ixion Linux - Software 2 06-17-2003 07:28 PM
compiler problem athenerx Linux - Newbie 1 07-29-2002 06:52 PM
compiler problem athenerx Programming 7 07-23-2002 02:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:27 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration