LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-04-2008, 05:18 AM   #1
new2lx
LQ Newbie
 
Registered: Feb 2008
Posts: 8

Rep: Reputation: 0
Can't compile C program


I'm new to Linux and new to programming. I want to use Linux shell as well as IDE to learn to program in C for a course I'm going to start. I am using Ubuntu and thought I installed everything necessary to run gcc. Here's my simple program:

Code:
#include <stdio.h>

int main(void)
{
        printf("here is some text.\n");

        getchar();

        return 0;
}
And here's what I get for output:

Code:
c$ gcc -o now now.c
now.c:1:19: error: stdio.h: No such file or directory
now.c: In function ‘main’:
now.c:5: warning: incompatible implicit declaration of built-in function ‘printf’
I assume I'm missing the file stdio.h file. I did a locate stdio.h but only got a perl response with nostdio.h, though I don't know if that's the way to go about checking if I have the file. I let the Synaptic Package Manager install all the dependencies it wanted to. I'm open to suggestions. Thank you
 
Old 03-04-2008, 07:30 AM   #2
grizly
Member
 
Registered: Nov 2006
Location: Melbourne Australia
Distribution: Centos, RHEL, Debian, Ubuntu, Mint
Posts: 128

Rep: Reputation: 16
You need the build files.. dev libraries and header files.

$sudo apt-get update

$sudo apt-get install build-essential
 
Old 03-04-2008, 07:36 AM   #3
ron7000
Member
 
Registered: Nov 2007
Location: CT
Posts: 248

Rep: Reputation: 26
try typing gcc --version
and report back what version it says you have.

I use opensuse 10.3 and I can't remember exactly but when installing opensuse there's a development section to the install that I had to select to get the full C compiler and libraries and such.

the file stdio.h should be located in /usr/include

in C programming, the default always has been for an include statement when it is just # include <xxx>
is that xxx resides by default in /usr/include. That is using <> to enclose the filename.

what you may try is # include </usr/include/stdio.h>

or if you find the file stdio.h and have it in your current directory, with your now.c program, you can
try # include "stdio.h". Using quotes around the *.h file will cause it to look in the current directory.

and when you compile, you can use the -I flag to tell the compiler what directories to look in for the
include files.
gcc -I/usr/include now.c is redundant, the compiler already looks there. If you throw an include file or have a directory of 3rd party files, it would be something like:

gcc -I/home/myaccount/thirdpartysoftware/include now.c -o now.out
 
Old 03-04-2008, 07:58 AM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Grizly's answer is probably correct, but since you mentioned Synaptic, I'll suggest another approach you might use (or save for the next time you have a similar question).

Go to the webpage
http://packages.ubuntu.com/

In the "Search the contents" section of that page, put the name of the missing file in the "Keyword" field. Since stdio.h is such a common string, you should restrict the search, probably with the third choice (Distribution and Architecture).

It still will find inexact matches, which you should ignore because you know you want exactly stdio.h (as the part after the last / in the name).

Even that leaves you many choices. Usually the simplest is best, which is /usr/include/stdio.h
Then you can see the package name to the right of that (in this case libc6-dev)
Then you can load that with Synaptic, retry your operation and see what else is missing.

For most files you won't have the pile of choices you get for stdio.h.

Grizly's answer is more complete this time. But I hope my answer can save you from needing to ask next time.

Last edited by johnsfine; 03-04-2008 at 07:59 AM.
 
Old 03-04-2008, 08:13 AM   #5
grizly
Member
 
Registered: Nov 2006
Location: Melbourne Australia
Distribution: Centos, RHEL, Debian, Ubuntu, Mint
Posts: 128

Rep: Reputation: 16
Its a front-end for apt.

I was wrong anyway, if you already have the compiler, you just need the libc6-dev library.

http://packages.ubuntu.com/feisty/libdevel/libc6-dev
 
Old 03-04-2008, 08:53 AM   #6
new2lx
LQ Newbie
 
Registered: Feb 2008
Posts: 8

Original Poster
Rep: Reputation: 0
You guys are great. I didn't have the libc6-dev package. Along with it linux-libc-dev was also added. Works like a champ now. Thanks!
 
Old 03-04-2008, 10:24 AM   #7
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by grizly View Post
Its a front-end for apt.
It's a front-end for apt that many people find more comfortable and understandable than using apt directly.

But Synaptic does not include a front-end for apt-file (so far as I understand) and if you search or ask for expert advice on install issues, you will find mainly apt answers rather than Synaptic answers.

I have hit the question "which not yet installed package includes this missing file?" several times in my short time using Linux.

So I wanted to spread the knowledge about the GUI version of dealing with a missing file from an unidentified uninstalled package.

Quote:
I was wrong anyway, if you already have the compiler, you just need the libc6-dev library.
I half understand using the apt stuff, so I assume someone giving plausible looking apt answers in threads like this knows more about apt than I know.
 
Old 03-05-2008, 12:35 AM   #8
new2lx
LQ Newbie
 
Registered: Feb 2008
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
I have hit the question "which not yet installed package includes this missing file?" several times in my short time using Linux.
Not being familiar enough with linux, almost two weeks now since I first did much of anything with it, I struggled with this exact question on this very subject. First I started out navigating in uncharted waters not certain whether I had everything I needed. I left it up to fate that the dependencies added would take care of everything. Then when I encountered a problem with what at the time I assumed was a missing file, I couldn't be sure how to get that file, nor what other files were also missing. The later point made under the assumption that as I progress beyond 'hello world!' I'll need other header files that may not be on my system.

I'll make a note of your suggestion on how to look for these files.

My introduction to the Linux world is showing it to be a truly friendly place with unselfish people willing to contribute and share. I'm reluctant to ask questions too quickly, as from experience (in the voice side of the telecom world) I know that there is so much to learn from shooting troubles. The experiences I've had asking for assistance have amazed me how quickly the/a solution is presented and I'm off to learn more. I see no barriers to learning linux, which I hope to do so I to can begin to contribute and assist others. Thank you all again.
 
Old 03-06-2008, 10:35 PM   #9
grizly
Member
 
Registered: Nov 2006
Location: Melbourne Australia
Distribution: Centos, RHEL, Debian, Ubuntu, Mint
Posts: 128

Rep: Reputation: 16
I wasn't trying to imply anything.. don't use the gui's myself, so can't really comment.

I just found the answer on the ubuntu forums tbh..
 
Old 03-07-2008, 05:59 AM   #10
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
I never looked in any ubuntu forum. I use Mepis and found the answer in a Mepis forum. Apparently the Mepis website has no tool similar to that one on the ubuntu website, but package naming is nearly identical between them, so when you find the package name for ubuntu (for some missing file) that usually tells you what to get from Synaptic in Mepis.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why I can't compile my c program? zhuqlfeixia Programming 6 12-12-2005 09:13 PM
Compile program ust Linux - General 5 05-31-2004 04:37 PM
program want compile dlm4444 Programming 10 09-26-2003 08:08 PM
Can't compile c++ program eg_wwkaa Programming 34 06-18-2003 08:59 PM
Compile qt program. hfawzy Linux - General 2 02-18-2003 10:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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