c programming
August 20, 2007 6:59 PM   Subscribe

I've just installed ubuntu, and I'm looking to do C programming from the terminal.

I've created the source code for my hello world program and tried to compile with gcc Hello.c command. Then it gives me the error "error: stdio.h: no such file or directory." Is there some command I need to install the standard library or something?
posted by amsterdam63 to Computers & Internet (12 answers total)
apt-get libc6-dev
posted by IronLizard at 7:02 PM on August 20, 2007

well, sudo apt-get libc6-dev, anyway
posted by IronLizard at 7:03 PM on August 20, 2007

"sudo apt-get install build-essential" should get you everything you need.

Also, is the source correct? #include <stdio.h> means from the standard system include directory; #include "stdio.h" means from the current directory. You almost certainly want the former form.
posted by Netzapper at 7:07 PM on August 20, 2007

You can also do this:

sudo apt-get install build-essential

And you may want to add install to the lines above if you use one of them.

All grabbed from this ubuntu forum post.
posted by IronLizard at 7:07 PM on August 20, 2007

Response by poster: Ok, I've done all of these and then it asks me for a password, so I put in the same one I use to log into the system and for some reason it isn't working. Any ideas?
posted by amsterdam63 at 8:23 PM on August 20, 2007

Response by poster: Actually, I think I got the password working, but then it says E: couldn't find package build-essential
posted by amsterdam63 at 8:27 PM on August 20, 2007

Off the top of my head, I'm guessing you don't have the repository for build-essentials in your /etc/apt/sources.list file, but I don't know off hand which repository you should add. Google around a bit, and definitely check this out: The Ububtu Guide - an invaluable resource.

(Note - I linked to the Edgy version because the section on build-essentials doesn't seem to be written for Feisty yet. Assuming you've installed Feisty, ie Ubuntu 7.04, the page you should be looking at for most other things is here.)
posted by cgg at 10:01 PM on August 20, 2007

Argh - Obviously, I can't spell Ubuntu... *sigh*. You know what I meant.
posted by cgg at 10:02 PM on August 20, 2007

Humm. It's very odd that build-essential wouldn't install. Have you tried running 'sudo apt-get update' and making sure there aren't any errors, and to make sure that your computer can contact the software repositories? Also, it might be more helpful to use Aptitude or Synaptic rather than 'apt-get' from the CLI, if you're not familiar with Debian package management. At least then you'll be able to see the list of available packages (or see that there's none available, in which case you have a bigger problem).

At any rate, 'build-essential' is just a metapackage -- it doesn't contain any unique software. Right now it consists of libc6-dev, gcc, g++, make, dpkg-dev, and a few other tools for other architectures. So you would just go through and install those manually. All of them should be in the standard repositories (according to the Ubuntu site, none of them should require enabling universe or multiverse).

But I really think that your problem may be in your syntax, as Netzapper suggests -- if you put '#include stdio.h' in your file, you will certainly (and correctly!) get an error; what you want is '#include < stdio.h>. The < and> signs are critical. (And without spaces around stdio.h ... but MeFi kept eating the signs if I didn't do that.)
posted by Kadin2048 at 10:20 PM on August 20, 2007

Oh and here is the link to the page about 'build-essential' in Ubuntu:


This is for Ubuntu Edgy ... if you use a different version of Ubuntu, replace 'edgy' with the name for your version ('feisty' or whatever).

It is definitely in the main repo, so you *shouldn't* have to do anything to your /etc/apt/sources.list file to get it to install ... unless you've changed something in there. (Try an apt-get update and see if it's working at all...)
posted by Kadin2048 at 10:24 PM on August 20, 2007

I think a default install starts with no repositories enabled except for the cd-rom. And I'm not at all sure build-essential is on the regular desktop CDs (it is on the alternate install cd.)

Anyway, what they said -- follow the Ubuntu guide and get your /etc/apt/sources.list in order and you should be compiling in no time.
posted by Zed_Lopez at 10:40 PM on August 20, 2007

The easiest way to enable all the repositories you're going to want for software development is to bring up System->Administration->Software Sources, turn on all five checkboxes on the Ubuntu Software tab, and click Close.

After you've done that, paste the following two lines into a terminal, one at a time:
sudo apt-get update
sudo apt-get install build-essential
If this works, but you still get compilation errors, mail me a copy of Hello.c and I'll see if I can replicate your issue on my Feisty box.
posted by flabdablet at 3:56 AM on August 21, 2007

« Older Useful Gift for Tibet/Nepal Photographer?   |   Where can I find real roast turkey in Princeton... Newer »
This thread is closed to new comments.