LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-14-2010, 10:49 AM   #1
farrukh_arshad
LQ Newbie
 
Registered: Dec 2010
Posts: 7

Rep: Reputation: 0
GCC unable to find "errno" when compiling on Ubuntu


Greetings All,

I am trying to compile a very simple program which uses errno variable, but I am getting compile error of not finding "errno" Given is my program.

1 #include <stdio.h>
2 #include <unistd.h>
3 #include <fcntl.h>
4 #include <error.h>
5 #include <string.h>
6
7 int main()
8 {
9 char data[256];
10 int fd;
11
12 if ( (fd = open("/dev/scull0", O_RDONLY)) == -1 )
13 {
14 printf("\nUnable to open driver file - Error <%s>\n", strerror(errno));
15 return 0;
16 }
17
18 while ( read(fd, data, (sizeof(char)*5)) )
19 {
20 printf("\nDriver Data = <%s>", data);
21 }
22
23 close(fd);
24 return 0;
25 }
~

When compiling I am getting the following error.


$ gcc -Wall player.c -o player
player.c: In function ‘main’:
player.c:14: error: ‘errno’ undeclared (first use in this function)
player.c:14: error: (Each undeclared identifier is reported only once
player.c:14: error: for each function it appears in.)

My compiler is
gcc 4.4.3

It appears to me my GCC is pointing to wrong system includes. Any thoughts ?

Regards.
 
Old 12-14-2010, 11:23 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Include errno.h
 
1 members found this post helpful.
Old 12-15-2010, 10:42 AM   #3
farrukh_arshad
LQ Newbie
 
Registered: Dec 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Smile

Thanks. I didn't realized I have just included error.h. Thanks a lot.
 
  


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
Compiled GCC, but the result "cannot find -lgcc_s" AlucardZero Linux - Software 3 11-24-2010 03:11 AM
"Unable to find medium with live File System" error in Ubuntu Installation. subashk80 Linux - Newbie 2 12-01-2009 11:49 PM
initial build of gcc: "cannot find -lc" xlq Linux From Scratch 5 06-03-2007 08:40 AM
GCC Compiling (Linux), "Segmentation Fault" Kenji Miyamoto Programming 2 01-13-2005 01:44 AM
"Compiling c prog using gcc in PHP" manikantha Programming 4 09-24-2004 04:05 AM

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

All times are GMT -5. The time now is 01:43 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