LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-20-2010, 09:40 PM   #1
utkarshrawat
Member
 
Registered: Jul 2007
Posts: 120

Rep: Reputation: 15
simple error


I have 3 C files but iam getting an error
Code:
/tmp/ccomGubn.o: In function `main':
main.c:(.text+0x17): undefined reference to `hye2'
collect2: ld returned 1 exit status
main.c
Code:
#include<stdio.h>
//#include<conio.h>
#include"hye2.h"
//extern int hye2();
main()
{
printf("\nHYE");
hye2();

}
hye2.c

Code:
int hye2()
{
printf("\nHYE2");
}
hye.h
Code:
int hye2();
It seems everything is ok but not getting were is the problem
 
Old 08-20-2010, 10:21 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
You need to show the commands that you used to compile and then link this program.

Because you have three files you need to include all of them in the process. The error that you have indicates that the linker doesn´t know about hye2.c

Finally, you may want to read up and consider using tools such as make.
 
Old 08-20-2010, 11:52 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
For example:
Quote:
gcc -o myprog main.c hye2.c
 
Old 08-21-2010, 03:00 AM   #4
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
You seem to have commented out the extern statement. I can understand commenting out conio.h, it being a DOS header.
 
Old 08-21-2010, 03:31 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Shouldn't the file hye2.c be named hye2.h?!?
 
Old 08-21-2010, 03:35 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I thought it was that "hye.h" should be "hye2.h" seeing it is being included but doesn't exist.
 
Old 08-21-2010, 09:25 PM   #7
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -
Quote:
Shouldn't the file hye.h be named hye2.h?!?
Irrelevant - the problem is a link error. #including the wrong header would result in a compile error.

"hye2.c" is named perfectly appropriately (although I would #include "hye.h" in hye2.c).

My guess is the OP probably just wasn't linking in "hye2.o" (separate compilation) or "hye2.c" (single-step compile/link, as in my example).

IMHO .. PSM

Last edited by paulsm4; 08-21-2010 at 09:27 PM.
 
  


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
simple error ...... can u help !!!! bhb Linux - Newbie 4 05-20-2010 07:51 AM
perl: simple one line replacement, simple error message! pwd_pwd_omg_pwd Programming 8 11-19-2008 12:53 PM
Simple SH Error - I hope... Micah Programming 5 06-28-2005 10:41 PM
Error for a very simple C program pkashyap Linux - Newbie 2 03-11-2004 10:24 AM
A simple error?? absolute0net Linux - Networking 3 07-08-2003 02:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:28 PM.

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