install c compiler

Asked by OccamsRazor

I'm using LTS 12.04 and want to compile c programs. I can't find any software on software center.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu software-center Edit question
Assignee:
No assignee Edit question
Solved by:
OccamsRazor
Solved:
Last query:
Last reply:
Revision history for this message
Warren Hill (warren-hill) said :
#1

There is a lot

First you need to install the basic tools open a terminal CTRL+ALT+T and enter

--------------------------------------------------------------------------------------
sudo apt-get install build-essential
-------------------------------------------------------------------------------------

Job done.

This installs the gcc compiler and there is information on how to use it here
http://developer.ubuntu.com/resources/programming-languages/c-and-c-plus-plus/

If you are doing a lot of programming you will want an Integrated Development Environment too (IDE). I use eclipse which you can install with the C and C++ plugins using the following command

----------------------------------------------------------------
sudo apt-get install-cdt
---------------------------------------------------------------

There are lots of other IDEs though and which you use is largely a matter of personal taste. Others may have an opinion on the best IDE.

Its worth asking the question about which IDE here
http://ubuntuforums.org/
but not now as its being upgraded today. Should be safe to ask tomorrow though

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#2

build-essential is a brilliant little package :)

Revision history for this message
Warren Hill (warren-hill) said :
#3

Correction IDE install.

You don't really need one but if you do want eclipse command should not have been

----------------------------------------------------------------
sudo apt-get install-cdt
---------------------------------------------------------------

but

----------------------------------------------------------------
sudo apt-get install eclipse-cdt
---------------------------------------------------------------

Revision history for this message
OccamsRazor (arijitshaw95) said :
#4

sudo apt-get install build-essential when i am doing this it shows
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package build-essential is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'build-essential' has no installation candidate

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#5

Make sure you have the universe repo enabled

Revision history for this message
OccamsRazor (arijitshaw95) said :
#6

yes, it is on http://s20.postimage.org/uohavjh4d/Screenshot_from_2013_03_01_10_16_06.png
but, there are some problems, when i select a software from universe source, it shows available from universe source. When i click "use this source", nothing happens, it shows "use this source" again.

Revision history for this message
Warren Hill (warren-hill) said :
#7

It should be there.

Try this

-----------------------------------------------------------------------------------------------------------------
sudo apt-get update; sudo apt-get dist-upgradesudo apt-get install build-essential
-----------------------------------------------------------------------------------------------------------------

and if it still does not work post the output of

------------------------------------------------------------------------------------
lsb_release -a; uname -a; sudo apt-cache policy build-essential
------------------------------------------------------------------------------------

You should see something similar to this

$ lsb_release -a; uname -a; sudo apt-cache policy build-essential
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.2 LTS
Release: 12.04
Codename: precise
Linux dell 3.2.0-38-generic-pae #61-Ubuntu SMP Tue Feb 19 12:39:51 UTC 2013 i686 i686 i386 GNU/Linux
build-essential:
  Installed: 11.5ubuntu2.1
  Candidate: 11.5ubuntu2.1
  Version table:
 *** 11.5ubuntu2.1 0
        500 http://gb.archive.ubuntu.com/ubuntu/ precise-updates/main i386 Packages
        100 /var/lib/dpkg/status
     11.5ubuntu2 0
        500 http://gb.archive.ubuntu.com/ubuntu/ precise/main i386 Packages

Revision history for this message
OccamsRazor (arijitshaw95) said :
#8

Yes, the build essential is downloaded now. But how to run it or install C now?

Revision history for this message
Warren Hill (warren-hill) said :
#9

First create a simple C file say "hello.c"

----------------------------------------------------------
#include <stdio.h>

int main (void){
    printf("Hello World\n");
    return (1);
}
-----------------------------------------------------------

Compile it

-------------------------------------------------------------
gcc -o hello hello.c
-------------------------------------------------------------

Run it

----------------------------------------------
./hello
----------------------------------------------

You should see

Hello World

If you do its working.

There are plenty of tutorials around on the net a good place to start is here
http://ubuntuforums.org/forumdisplay.php?f=39

As I said yesterday If you are looking for an IDE similar to Visual Studio for example I use eclipse but there are others such as Code::Blocks, Geeny, etc.

You can install eclipse with

----------------------------------------------------------------
sudo apt-get install eclipse-cdt
---------------------------------------------------------------

You will find more programmers on the Ubuntu forums who can help you too.

The forums are back up now.
http://ubuntuforums.org/forum.php

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#10

You can compile C and C++ in the terminal, or install and IDE and you can use a GUI to code etc.

Revision history for this message
OccamsRazor (arijitshaw95) said :
#11

In the second line it shows
bash: syntax error near unexpected token `"hello world"'

Revision history for this message
OccamsRazor (arijitshaw95) said :
#12

I have installed Code::Blocks and when I am running a program it shows:
/media/.../hello: permission denied
what should I do?

Revision history for this message
OccamsRazor (arijitshaw95) said :
#13

Finally it is running nice. Much thanks to Warren and actionparsnip.