LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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-07-2007, 12:40 AM   #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-07-2007, 12:44 AM   #2
rocket357
Member
 
Registered: Mar 2007
Location: 127.0.0.1
Distribution: OpenBSD-CURRENT
Posts: 485
Blog Entries: 159

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-07-2007, 12:56 AM   #3
hegdeshashi
Member
 
Registered: Dec 2005
Posts: 73
Blog Entries: 3

Original Poster
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, 01:01 AM   #4
rocket357
Member
 
Registered: Mar 2007
Location: 127.0.0.1
Distribution: OpenBSD-CURRENT
Posts: 485
Blog Entries: 159

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

Original Poster
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, 05: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, 11:54 PM   #7
hegdeshashi
Member
 
Registered: Dec 2005
Posts: 73
Blog Entries: 3

Original Poster
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


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


All times are GMT -5. The time now is 08:37 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration