how to instal g++ compiler and C++ in ubuntu??

Asked by amit

can any one help me to install g++ compiler and C++ in the ubuntu ??

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gnome-nettool Edit question
Assignee:
No assignee Edit question
Solved by:
Cesare Tirabassi
Solved:
Last query:
Last reply:
Revision history for this message
Olivier Lemaire (olivier-lemaire) said :
#1

Two quick ways :
 . from command line, just sudo apt-get update && sudo apt-get install g++
  (g++ is the GNU C++ compiler)
 . from the menu bar / system / Package Manager (synaptic), search 'C++' in Development. Find 'g++' and select to install it

When you wander what the name of the package that could fits you need, use (command line) : apt-cache search KEYWORD (where 'KEYWORD' best define what your are looking for). Of course, you can use pipes and grep to better define what you're looking for.

hope this'll help you.

Revision history for this message
amit (amityy2002) said :
#2

when i tried by command line as u said :
something like this happened and the nothing then nothing happened

Get:1 http://security.ubuntu.com feisty-security Release.gpg [191B]
Ign http://security.ubuntu.com feisty-security/main Translation-en_IN
Ign http://security.ubuntu.com feisty-security/universe Translation-en_IN
Get:2 http://in.archive.ubuntu.com feisty Release.gpg [191B]
Ign http://in.archive.ubuntu.com feisty/main Translation-en_IN
Get:3 http://security.ubuntu.com feisty-security Release [50.9kB]
Ign http://in.archive.ubuntu.com feisty/restricted Translation-en_IN
Ign http://in.archive.ubuntu.com feisty/universe Translation-en_IN
Ign http://in.archive.ubuntu.com feisty/multiverse Translation-en_IN
Ign http://in.archive.ubuntu.com feisty/main Translation-en_IN
Ign http://in.archive.ubuntu.com feisty/universe Translation-en_IN
Get:4 http://security.ubuntu.com feisty-security/main Packages [29.4kB]

And when i tried by system packege manager something like this happened

W: Duplicate sources.list entry http://in.archive.ubuntu.com feisty/main Packages (/var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_feisty_main_binary-i386_Packages)
W: Duplicate sources.list entry http://in.archive.ubuntu.com feisty/universe Packages (/var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_feisty_universe_binary-i386_Packages)
W: Duplicate sources.list entry http://in.archive.ubuntu.com feisty-updates/main Packages (/var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_feisty-updates_main_binary-i386_Packages)

what should i do ???:

Revision history for this message
amit (amityy2002) said :
#3

Actually the problem is it is not connecting to the net???
and giveing following error

W: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/l/linux-source-2.6.20/linux-libc-dev_2.6.20-16.28_i386.deb
  407 Proxy Authentication Required

Revision history for this message
Daniel Nascimento (nascimento) said :
#4

Hello Amit..

Could u please post to me all results given by the command:.

#] apt-get update

Remember to use "sudo" (or other root privileges)

Ps:. sorry about my bad english..iv'ed learned that by myself... lol...

Paz:.

Revision history for this message
amit (amityy2002) said :
#5

thanks budddy your English is as good as anyone else this are the results which i got ::

amit@amit:~$ sudo apt-get update
password:
Get:1 http://in.archive.ubuntu.com feisty Release.gpg [191B]
Ign http://in.archive.ubuntu.com feisty/main Translation-en_IN
Ign http://in.archive.ubuntu.com feisty/restricted Translation-en_IN
Ign http://in.archive.ubuntu.com feisty/universe Translation-en_IN
Ign http://in.archive.ubuntu.com feisty/multiverse Translation-en_IN
Ign http://in.archive.ubuntu.com feisty/main Translation-en_IN
Ign http://in.archive.ubuntu.com feisty/universe Translation-en_IN
Get:2 http://in.archive.ubuntu.com feisty-updates Release.gpg [191B]
Ign http://in.archive.ubuntu.com feisty-updates/main Translation-en_IN
Ign http://in.archive.ubuntu.com feisty-updates/restricted Translation-en_IN
Ign http://in.archive.ubuntu.com feisty-updates/main Translation-en_IN
Ign http://in.archive.ubuntu.com feisty-updates/universe Translation-en_IN
Get:3 http://in.archive.ubuntu.com feisty-security Release.gpg [191B]
Ign http://in.archive.ubuntu.com feisty-security/main Translation-en_IN
Ign http://in.archive.ubuntu.com feisty-security/restricted Translation-en_IN
Ign http://in.archive.ubuntu.com feisty-security/universe Translation-en_IN
Ign http://in.archive.ubuntu.com feisty-security/multiverse Translation-en_IN
Get:4 http://in.archive.ubuntu.com feisty Release [57.2kB]
Hit http://in.archive.ubuntu.com feisty-updates Release
Get:5 http://security.ubuntu.com feisty-security Release.gpg [191B]
Ign http://security.ubuntu.com feisty-security/main Translation-en_IN
Ign http://security.ubuntu.com feisty-security/universe Translation-en_IN
Hit http://in.archive.ubuntu.com feisty-security Release
Hit http://security.ubuntu.com feisty-security Release
Hit http://in.archive.ubuntu.com feisty/main Packages
Hit http://security.ubuntu.com feisty-security/main Packages
Hit http://in.archive.ubuntu.com feisty/restricted Packages
Hit http://security.ubuntu.com feisty-security/universe Packages
Hit http://in.archive.ubuntu.com feisty/main Sources
Hit http://in.archive.ubuntu.com feisty/restricted Sources
Hit http://in.archive.ubuntu.com feisty/universe Packages
Hit http://in.archive.ubuntu.com feisty/universe Sources
Get:6 http://in.archive.ubuntu.com feisty/multiverse Packages [148kB]
Hit http://in.archive.ubuntu.com feisty/multiverse Sources
Hit http://in.archive.ubuntu.com feisty/main Packages
Hit http://in.archive.ubuntu.com feisty/universe Packages
Hit http://in.archive.ubuntu.com feisty-updates/main Packages
Hit http://in.archive.ubuntu.com feisty-updates/restricted Packages
Get:7 http://in.archive.ubuntu.com feisty-updates/main Sources [5164B]
99% [7 Sources bzip2 0] [Connecting to netmon.iitb.ac.in (10.200.13.50)] 29.9kB/s 0s
bzip2: Data integrity error when decompressing.
        Input file = (stdin), output file = (stdout)

It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.

You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.

Err http://in.archive.ubuntu.com feisty-updates/main Sources
  Sub-process bzip2 returned an error code (2)
Hit http://in.archive.ubuntu.com feisty-updates/restricted Sources
Hit http://in.archive.ubuntu.com feisty-updates/main Packages
Hit http://in.archive.ubuntu.com feisty-updates/universe Packages
Hit http://in.archive.ubuntu.com feisty-security/main Packages
Get:8 http://in.archive.ubuntu.com feisty-security/restricted Packages [6350B]
Hit http://in.archive.ubuntu.com feisty-security/main Sources
Hit http://in.archive.ubuntu.com feisty-security/restricted Sources
Get:9 http://in.archive.ubuntu.com feisty-security/universe Packages [14.0kB]
Hit http://in.archive.ubuntu.com feisty-security/universe Sources
Get:10 http://in.archive.ubuntu.com feisty-security/multiverse Packages [3378B]
Hit http://in.archive.ubuntu.com feisty-security/multiverse Sources
Fetched 229kB in 21s (10.8kB/s)
Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/feisty-updates/main/source/Sources.bz2 Sub-process bzip2 returned an error code (2)
Reading package lists... Done

Revision history for this message
amit (amityy2002) said :
#6

thanks to all my friends
now i have got g++ installed......but still there is a problem coming that is when i am running a c++ code it is giving the error like this
can u sort out what is the problem there (as i think that C++ lib files are not there )

amit@amit:~$ g++ p.c -o simple
In file included from /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/iostream.h:31,
                 from p.c:2:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
amit@amit:~$

Revision history for this message
Best Cesare Tirabassi (norsetto) said :
#7

Amit,

if your original problem is solved please mark it so and open a new ticket.

Revision history for this message
amit (amityy2002) said :
#8

Thanks Cesare Tirabassi, that solved my question.

Revision history for this message
Cesare Tirabassi (norsetto) said :
#9

Thanks,

but you should acknowledge the guy that helped you solve the problem.

Revision history for this message
Daniel Nascimento (nascimento) said :
#10

I think he can still use this ticket, cause his update in apt sources get some trouble using that mirror..

look:

            bzip2: Data integrity error when decompressing.
            Input file = (stdin), output file = (stdout)

            It is possible that the compressed file(s) have become corrupted.
            You can use the -tvv option to test integrity of such files.

            You can use the `bzip2recover' program to attempt to recover
            data from undamaged sections of corrupted files.

Let's give a "blind" shot...

try to purge the fles you have downloaded like this:.

#] aptitude purge package_name

Then, use this source list for download - just for test, make a backup before:

#] cp /etc/apt/sources.list sources.list-BACKUP

Then edit the sources.list, remove all sources and put theese insteed:

       deb http://br.archive.ubuntu.com/ubuntu/ feisty-backports main restricted universe multiverse
       deb-src http://br.archive.ubuntu.com/ubuntu/ feisty-backports main restricted universe multiverse

       deb http://security.ubuntu.com/ubuntu feisty-security main restricted
       deb-src http://security.ubuntu.com/ubuntu feisty-security main restricted
       deb http://security.ubuntu.com/ubuntu feisty-security universe
       deb-src http://security.ubuntu.com/ubuntu feisty-security universe
       deb http://security.ubuntu.com/ubuntu feisty-security multiverse
       deb-src http://security.ubuntu.com/ubuntu feisty-security multiverse

If youŕe using an old-stable ubuntu (edgy) just change the word FEISTY for edgy like the exemple below:
       deb-src http://security.ubuntu.com/ubuntu edgy-security multiverse

After that, do some update:.

#] apt-get update

And try to install the packages GCC and C++ ...
Let me know if that help u out!

;-) See yah!

Revision history for this message
amit (amityy2002) said :
#11

thaks to all u buddies i am really happy now as my problem is solved.........

Revision history for this message
jegan (jeganmhn) said :
#12

hi all,
i had installed ubuntu recently..when i tried to install other softwares in during ./configure it gave an error like gcc folder not found..
whats the problem and how do i solve it..i am not having net connection so i cannot download..but i can download on my windows machine and run get it here..
please help me

Revision history for this message
amit (amityy2002) said :
#13

hi ,
Actually most of the software programs are written in c and to run those we need a compiler gcc, thats why the error is coming like gcc not found as it is not in your system.
Now you can do two things :
1) simplest way :
    if you are able to connect with the internet then in the command line type :
     sudo apt-get install gcc
     it will ask you root passward type that and then everything is done just hit yes at every questions then.
2) or gc is also in the ubuntu installation CD you can find it at:
     /pool/main/g/
    and install all the packages of g there your problem will be solved

Revision history for this message
sufal (sufal-ce03) said :
#14

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

sufal@sufal-desktop:~$ sudo apt-get update && sudo apt-get install g++
[sudo] password for sufal:
Get:1 http://security.ubuntu.com karmic-security Release.gpg [189B]
Ign http://security.ubuntu.com karmic-security/main Translation-en_US
Get:2 http://bd.archive.ubuntu.com karmic Release.gpg [189B]
Ign http://bd.archive.ubuntu.com karmic/main Translation-en_US
Ign http://security.ubuntu.com karmic-security/restricted Translation-en_US
Ign http://security.ubuntu.com karmic-security/universe Translation-en_US
Ign http://security.ubuntu.com karmic-security/multiverse Translation-en_US
Get:3 http://security.ubuntu.com karmic-security Release [44.1kB]
Ign http://bd.archive.ubuntu.com karmic/restricted Translation-en_US
Ign http://bd.archive.ubuntu.com karmic/universe Translation-en_US
Ign http://bd.archive.ubuntu.com karmic/multiverse Translation-en_US
Get:4 http://bd.archive.ubuntu.com karmic-updates Release.gpg [189B]
Ign http://bd.archive.ubuntu.com karmic-updates/main Translation-en_US
Ign http://bd.archive.ubuntu.com karmic-updates/restricted Translation-en_US
Ign http://bd.archive.ubuntu.com karmic-updates/universe Translation-en_US
Ign http://bd.archive.ubuntu.com karmic-updates/multiverse Translation-en_US
Get:5 http://bd.archive.ubuntu.com karmic Release [65.9kB]
Get:6 http://security.ubuntu.com karmic-security/main Packages [98.3kB]
Get:7 http://bd.archive.ubuntu.com karmic-updates Release [44.1kB]
Get:8 http://security.ubuntu.com karmic-security/restricted Packages [14B]
Get:9 http://security.ubuntu.com karmic-security/main Sources [29.2kB]
Get:10 http://bd.archive.ubuntu.com karmic/main Packages [1,353kB]
Get:11 http://security.ubuntu.com karmic-security/restricted Sources [14B]
Get:12 http://security.ubuntu.com karmic-security/universe Packages [52.6kB]
Get:13 http://security.ubuntu.com karmic-security/universe Sources [8,743B]
Get:14 http://security.ubuntu.com karmic-security/multiverse Packages [1,666B]
Get:15 http://security.ubuntu.com karmic-security/multiverse Sources [577B]
Get:16 http://bd.archive.ubuntu.com karmic/restricted Packages [7,971B]
Get:17 http://bd.archive.ubuntu.com karmic/main Sources [640kB]
Get:18 http://bd.archive.ubuntu.com karmic/restricted Sources [3,270B]
Get:19 http://bd.archive.ubuntu.com karmic/universe Packages [5,133kB]
Get:20 http://bd.archive.ubuntu.com karmic/universe Sources [2,795kB]
Get:21 http://bd.archive.ubuntu.com karmic/multiverse Packages [190kB]
Get:22 http://bd.archive.ubuntu.com karmic/multiverse Sources [116kB]
Get:23 http://bd.archive.ubuntu.com karmic-updates/main Packages [213kB]
Get:24 http://bd.archive.ubuntu.com karmic-updates/restricted Packages [14B]
Get:25 http://bd.archive.ubuntu.com karmic-updates/main Sources [63.2kB]
Get:26 http://bd.archive.ubuntu.com karmic-updates/restricted Sources [14B]
Get:27 http://bd.archive.ubuntu.com karmic-updates/universe Packages [130kB]
Get:28 http://bd.archive.ubuntu.com karmic-updates/universe Sources [31.1kB]
Get:29 http://bd.archive.ubuntu.com karmic-updates/multiverse Packages [10.8kB]
Get:30 http://bd.archive.ubuntu.com karmic-updates/multiverse Sources [4,932B]
Fetched 11.0MB in 14min 12s (13.0kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  cpp-4.4 g++-4.4 gcc-4.4 gcc-4.4-base libgcc1 libgomp1 libstdc++6
  libstdc++6-4.4-dev
Suggested packages:
  gcc-4.4-locales g++-multilib g++-4.4-multilib gcc-4.4-doc libstdc++6-4.4-dbg
  gcc-4.4-multilib libmudflap0-4.4-dev libgcc1-dbg libgomp1-dbg
  libmudflap0-dbg libcloog-ppl0 libppl-c2 libppl7 libstdc++6-4.4-doc
The following NEW packages will be installed:
  g++ g++-4.4 libstdc++6-4.4-dev
The following packages will be upgraded:
  cpp-4.4 gcc-4.4 gcc-4.4-base libgcc1 libgomp1 libstdc++6
6 upgraded, 3 newly installed, 0 to remove and 273 not upgraded.
Need to get 13.3MB of archives.
After this operation, 20.8MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://bd.archive.ubuntu.com karmic-updates/main gcc-4.4-base 4.4.1-4ubuntu9 [113kB]
Get:2 http://bd.archive.ubuntu.com karmic-updates/main libstdc++6 4.4.1-4ubuntu9 [346kB]
Get:3 http://bd.archive.ubuntu.com karmic-updates/main libgomp1 4.4.1-4ubuntu9 [24.2kB]
Get:4 http://bd.archive.ubuntu.com karmic-updates/main cpp-4.4 4.4.1-4ubuntu9 [3,544kB]
Get:5 http://bd.archive.ubuntu.com karmic-updates/main gcc-4.4 4.4.1-4ubuntu9 [2,976kB]
Get:6 http://bd.archive.ubuntu.com karmic-updates/main libgcc1 1:4.4.1-4ubuntu9 [55.0kB]
Get:7 http://bd.archive.ubuntu.com karmic-updates/main libstdc++6-4.4-dev 4.4.1-4ubuntu9 [1,490kB]
Get:8 http://bd.archive.ubuntu.com karmic-updates/main g++-4.4 4.4.1-4ubuntu9 [4,701kB]
Get:9 http://bd.archive.ubuntu.com karmic/main g++ 4:4.4.1-1ubuntu2 [1,446B]
Fetched 13.3MB in 20min 59s (10.5kB/s)
(Reading database ... 114040 files and directories currently installed.)
Preparing to replace gcc-4.4-base 4.4.1-4ubuntu8 (using .../gcc-4.4-base_4.4.1-4ubuntu9_i386.deb) ...
Unpacking replacement gcc-4.4-base ...
Setting up gcc-4.4-base (4.4.1-4ubuntu9) ...
(Reading database ... 114040 files and directories currently installed.)
Preparing to replace libstdc++6 4.4.1-4ubuntu8 (using .../libstdc++6_4.4.1-4ubuntu9_i386.deb) ...
Unpacking replacement libstdc++6 ...
Setting up libstdc++6 (4.4.1-4ubuntu9) ...

Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
(Reading database ... 114040 files and directories currently installed.)
Preparing to replace libgomp1 4.4.1-4ubuntu8 (using .../libgomp1_4.4.1-4ubuntu9_i386.deb) ...
Unpacking replacement libgomp1 ...
Preparing to replace cpp-4.4 4.4.1-4ubuntu8 (using .../cpp-4.4_4.4.1-4ubuntu9_i386.deb) ...
Unpacking replacement cpp-4.4 ...
Preparing to replace gcc-4.4 4.4.1-4ubuntu8 (using .../gcc-4.4_4.4.1-4ubuntu9_i386.deb) ...
Unpacking replacement gcc-4.4 ...
Preparing to replace libgcc1 1:4.4.1-4ubuntu8 (using .../libgcc1_1%3a4.4.1-4ubuntu9_i386.deb) ...
Unpacking replacement libgcc1 ...
Processing triggers for man-db ...
Setting up libgcc1 (1:4.4.1-4ubuntu9) ...

Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Selecting previously deselected package libstdc++6-4.4-dev.
(Reading database ... 114040 files and directories currently installed.)
Unpacking libstdc++6-4.4-dev (from .../libstdc++6-4.4-dev_4.4.1-4ubuntu9_i386.deb) ...
Selecting previously deselected package g++-4.4.
Unpacking g++-4.4 (from .../g++-4.4_4.4.1-4ubuntu9_i386.deb) ...
Selecting previously deselected package g++.
Unpacking g++ (from .../g++_4%3a4.4.1-1ubuntu2_i386.deb) ...
Processing triggers for man-db ...
Setting up libgomp1 (4.4.1-4ubuntu9) ...

Setting up cpp-4.4 (4.4.1-4ubuntu9) ...
Setting up gcc-4.4 (4.4.1-4ubuntu9) ...
Setting up libstdc++6-4.4-dev (4.4.1-4ubuntu9) ...
Setting up g++-4.4 (4.4.1-4ubuntu9) ...
Setting up g++ (4:4.4.1-1ubuntu2) ...
update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode.

Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
sufal@sufal-desktop:~$
sufal@sufal-desktop:~$

Revision history for this message
sufal (sufal-ce03) said :
#15

what should i give now??