PDA

View Full Version : [SOLVED] gcc/g++ help for ubuntu 8.04



AceDip
July 16th, 2008, 04:36 PM
well i am trying hard to shift to linux completely{dont like microsoft)but this one problem is a big hinderence.
well now, i made a simple cpp file as


#include<iostream>
using namespace std;
int main() {
cout<<"hello";
}

and when i compile it as

gcc <filename>
its gives following output
Bash:Syntax error unexpected token 'newline'
and on running the file as

./a.out it gives this
no such file or directory
and in the package manager i have gcc already installed but g++ is not there but i guess isnt gcc enough?
well anyways kindly help so that i can do cpp again.

era86
July 16th, 2008, 04:40 PM
First, make sure you return an int. What is the file named? What are you typing exactly on the cl?

Bachstelze
July 16th, 2008, 04:43 PM
Install build-essential.

elmoosecapitan
July 16th, 2008, 04:44 PM
I also want to emphasize adding the line:

return 0;

right before you end you main function.

Also, it might help (sometimes) to include the file path, i.e. ~/Desktop/filename.cpp or /home/username/Desktop/filename.cpp

AceDip
July 16th, 2008, 04:44 PM
returning this int isnt a trouble,ISO C++ supports it.
My file name is new.cpp
and i'm typing
gcc <new>
then
./a.out

Tony Flury
July 16th, 2008, 04:46 PM
not returning an Int would not give a bash script error - it might give a compiler warning, but i am not sure that gcc or g++ is that strict.

Make sure you install the build-essentials package



sudo apt-get install build-essential


As era says though - provide us with all the command lines you enter - and the exact output.

And finally - when you are including code or cli output in posts on this forum - make sure that you use the code tags - it preserves the formatting and makes it easier to read.

Tony Flury
July 16th, 2008, 04:50 PM
returning this int isnt a trouble,ISO C++ supports it.
My file name is new.cpp
and i'm typing
gcc <new>
then
./a.out

Trying the command :


g++ new.cpp -o a.out

to compile your code, and not what you have (actually -o a.out is superfluous but i think it is a good habit to explicitly name the output executable)

I think the gcc command line is getting confused with you using <new>, as it will look like you are piping input and output ...

sujoy
July 16th, 2008, 04:51 PM
for compiling cpp with gcc you need to add the libstdc lib.

its something like, gcc -o name name.cpp -libstdc

or better use g++

AceDip
July 16th, 2008, 06:11 PM
When i type
gcc new.cpp
its gives following output

gcc:error trying to exec 'cclplus': execvp: No such file or directory
and even if i type

gcc new.cpp -o a.out
it gives the same above output

Tony Flury
July 16th, 2008, 06:23 PM
did you install build-essentials - and the compiler :


sudo apt-get install build-essential
sudo apt-get install g++


one positive thing from all of this : at least now you are getting some form of compiler error - and not a scripting error - so you have made a step forward.

AceDip
July 16th, 2008, 06:34 PM
ya true step forward is definitely a conclusion.
gcc is already there in my package manager and when i select it, it asks me to either remove it or remove all.
so that seems its already there and one thing more, when i write

gcc
it gives output

no input file
and it asks for the package builder when i type g++ instead

appi2012
July 16th, 2008, 06:36 PM
I don't know why this should make a difference, but I use the extension .C rather than .cpp. Just a thought;)

Tony Flury
July 16th, 2008, 06:40 PM
ya true step forward is definitely a conclusion.
gcc is already there in my package manager and when i select it, it asks me to either remove it or remove all.
so that seems its already there and one thing more, when i write

gcc
it gives output

no input file
and it asks for the package builder when i type g++ instead

gcc is a general compiler - it will do a lot more than just c (or c++) so just having the gcc command installed does not mean you have a c or c++ compiler.

did you install the g++ package with the apt-get instruction i gave you ?

AceDip
July 16th, 2008, 06:47 PM
i do not have g++ in the package manager

elmoosecapitan
July 16th, 2008, 06:52 PM
You should be able to download g++ via a terminal using the sudo apt-get command. Typing in


g++

will give you instructions for installing with a terminal. Then type


$ g++ ./new.cpp
$ ./a.out



To answer you question, using '.C' does make a slight difference when trying to compile. I generally try to stay with '.cpp'.

cheers

AceDip
July 16th, 2008, 06:54 PM
running the apt-get instruction,gives

0 installed 0 removes 0 upgraded
in short it cant find g++ package or rather i think its not there.
but gcc is there in the package manager and installed.as i told u asks for its removal when i click on it there and for its installation.

AceDip
July 16th, 2008, 06:57 PM
here another problem arises.My internet is working from windows not ununtu,by phone vendor does support the phone cable which is connected to my
comp.so i'm on windows now.

Tony Flury
July 16th, 2008, 07:03 PM
which sources do you have enabled (give us the contents of your /etc/apt/source.lst file) - it is very odd that you don't have the g++ package available

does the apt-get say that g++ is not available or does it say it is already installed - on my system :



sudo apt-get install g++

Reading package lists... Done
Building dependency tree
Reading state information... Done
g++ is already the newest version.
g++ set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.


As you can see the last line is similar to yours - but the key line is :


g++ is already the newest version.


As has already been mentioned - it is a good idea to copy and paste all the output into any reply - often the last line is a summary - and the error is somewhat earlier

DGortze380
July 16th, 2008, 08:12 PM
just use g++.
You're problem appears to be a syntax error in typing the command.

for example.
my source file is call: howToCompile.cpp
and is located in /home/user



g++ /home/user/howToCompile.cpp -o howToCompile


As far as the internet issue, that is the reason apt-get is not working.

AceDip
July 17th, 2008, 04:51 AM
did you install build-essentials - and the compiler :


sudo apt-get install build-essential
sudo apt-get install g++


one positive thing from all of this : at least now you are getting some form of compiler error - and not a scripting error - so you have made a step forward.

i typed these instructions and following was the output

sudo apt-get install build essential

Reading package list...Done
Building dependency tree
Reading state information...Done
E: Couldn't find package build

and the next command


sudo apt-get install g++

Reading package list...Done
Building dependency tree
Reading state information...Done
E: Couldn't find package g

but this one gave some anticipated output,which you can comprehend


sudo apt-get install gcc

Reading package list...Done
Building dependency tree
Reading state information...Done
gcc is already the newest version.
0 upgraded,0 newly installed,0 to remove and 0 not upgraded.

AceDip
July 17th, 2008, 05:02 AM
did you install build-essentials - and the compiler :


sudo apt-get install build-essential
sudo apt-get install g++


one positive thing from all of this : at least now you are getting some form of compiler error - and not a scripting error - so you have made a step forward.

i typed these instructions and following was the output

sudo apt-get install build essential

Reading package list...Done
Building dependency tree
Reading state information...Done
E: Couldn't find package build

and the next command


sudo apt-get install g++

Reading package list...Done
Building dependency tree
Reading state information...Done
E: Couldn't find package g

but this one gave some anticipated output,which you can comprehend


sudo apt-get install gcc

Reading package list...Done
Building dependency tree
Reading state information...Done
gcc is already the newest version.
0 upgraded,0 newly installed,0 to remove and 0 not upgraded.

era86
July 17th, 2008, 06:27 AM
Should be "sudo apt-get install build-essential" with the dash.

Tony Flury
July 17th, 2008, 07:28 AM
i typed these instructions and following was the output

sudo apt-get install build essential

Reading package list...Done
Building dependency tree
Reading state information...Done
E: Couldn't find package build

and the next command


sudo apt-get install g++

Reading package list...Done
Building dependency tree
Reading state information...Done
E: Couldn't find package g

but this one gave some anticipated output,which you can comprehend


sudo apt-get install gcc

Reading package list...Done
Building dependency tree
Reading state information...Done
gcc is already the newest version.
0 upgraded,0 newly installed,0 to remove and 0 not upgraded.

As i pointed out gcc is only part of the compiler, you need the g++ module as well. I can only assume that the shell that you use misunderstood the '+' sign on the command line - which is odd : Try this instead :



sudo apt-get install "g++"


also as era pointed out - you should be using build-essential - i had included the "-" in my posts (copy and paste is your friend).

AceDip
July 17th, 2008, 08:03 PM
hey Tony and Era.i tried as u guys said and this how it comes

sudo apt-get install build-essential

Reading package list...Done
Building dependency tree
Reading state information...Done
E: Couldn't find package build-essential

and


sudo apt-get install "g++"

Reading package list...Done
Building dependency tree
Reading state information...Done
E: Couldn't find package g

so wat does this mean man...

era86
July 17th, 2008, 08:10 PM
I would look into your sources.list file for proper repositories. Just do a gedit on /usr/apt/sources.list and show us the contents of that file.

AceDip
July 17th, 2008, 08:12 PM
hey Tony and Era.i tried as u guys said and this how it comes

sudo apt-get install build-essential

Reading package list...Done
Building dependency tree
Reading state information...Done
E: Couldn't find package build-essential

and


sudo apt-get install "g++"

Reading package list...Done
Building dependency tree
Reading state information...Done
E: Couldn't find package g

so wat does this mean man...

Dougie187
July 17th, 2008, 08:17 PM
Did you try to type

sudo apt-get update
before you did the two installs?

Exact Code:


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

AceDip
July 17th, 2008, 08:17 PM
I would look into your sources.list file for proper repositories. Just do a gedit on /usr/apt/sources.list and show us the contents of that file.
look i'm not very familiar with wat u are talking about..can u please tell me wat exact code do i have to write there..

DGortze380
July 17th, 2008, 08:18 PM
look i'm not very familiar with wat u are talking about..can u please tell me wat exact code do i have to write there..

Open a terminal (accessories>terminal) and copy and paste the output of:




cat /usr/apt/sources.list

Tony Flury
July 17th, 2008, 08:19 PM
ok - what shell are you running ? do the following command and post the results :



echo $SHELL


The commands i have provided work in the bash shell.

Alternatively - do you not have the Synaptic Package Manager installed on your System ? It normally resides under the System -> Administration menu. the g++ package should be there.

Dougie187
July 17th, 2008, 08:22 PM
rather then looking for G++ specifically look for build-essential. that should have g++ in it.

AceDip
July 17th, 2008, 08:25 PM
ok - what shell are you running ? do the following command and post the results :



echo $SHELL


The commands i have provided work in the bash shell.

Alternatively - do you not have the Synaptic Package Manager installed on your System ? It normally resides under the System -> Administration menu. the g++ package should be there.
I have checked the Synaptic Package Manager,its showing a list a packages..i guess the package manager is installed??
and g++ is not there while gcc is.

Dougie187
July 17th, 2008, 08:34 PM
You should try some of the other suggestions in this post.

johnnybravo666
July 17th, 2008, 08:39 PM
This has already been mentioned but post the results of this command


cat /etc/apt/sources.list

AceDip
July 17th, 2008, 08:50 PM
ok - what shell are you running ? do the following command and post the results :



echo $SHELL


The commands i have provided work in the bash shell.

Alternatively - do you not have the Synaptic Package Manager installed on your System ? It normally resides under the System -> Administration menu. the g++ package should be there.


echo $SHELL


/bin/bash

as i have mentioned package manager is showing the list of packages..so i guess the package manager is installed.it is not showing g++.

AceDip
July 17th, 2008, 08:55 PM
This has already been mentioned but post the results of this command


cat /etc/apt/sources.list


/etc/apt/sources.list

bash: /etc/apt/sources.list: Permission denied

DGortze380
July 17th, 2008, 08:58 PM
did you remember the cat command?

try



sudo cat /etc/apt/sources.list


although I don't think you should need sudo.

Natr0n
July 17th, 2008, 09:10 PM
here another problem arises.My internet is working from windows not ununtu,by phone vendor does support the phone cable which is connected to my
comp.so i'm on windows now.
If you still haven't fixed this you're not going to be able to use apt-get or the package manager to install anything. You need to fix your internet connection first, then do
sudo apt-get install build-essential

AceDip
July 17th, 2008, 09:21 PM
This has already been mentioned but post the results of this command


cat /etc/apt/sources.list

here is it


cat /etc/apt/sources.list


#deb cdrom:[Ubuntu 8.04 _Hardy Heron_ - Release i386 (20080423)]/ hardy main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.

deb http://in.archive.ubuntu.com/ubuntu/ hardy main restricted
deb-src http://in.archive.ubuntu.com/ubuntu/ hardy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://in.archive.ubuntu.com/ubuntu/ hardy-updates main restricted
deb-src http://in.archive.ubuntu.com/ubuntu/ hardy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## universe WILL NOT receive any review or updates from the Ubuntu security
## team.
deb http://in.archive.ubuntu.com/ubuntu/ hardy universe
deb-src http://in.archive.ubuntu.com/ubuntu/ hardy universe
deb http://in.archive.ubuntu.com/ubuntu/ hardy-updates universe
deb-src http://in.archive.ubuntu.com/ubuntu/ hardy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://in.archive.ubuntu.com/ubuntu/ hardy multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ hardy multiverse
deb http://in.archive.ubuntu.com/ubuntu/ hardy-updates multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ hardy-updates multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb http://in.archive.ubuntu.com/ubuntu/ hardy-backports main restricted universe multiverse
# deb-src http://in.archive.ubuntu.com/ubuntu/ hardy-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository. This software is not part of Ubuntu, but is
## offered by Canonical and the respective vendors as a service to Ubuntu
## users.
# deb http://archive.canonical.com/ubuntu hardy partner
# deb-src http://archive.canonical.com/ubuntu hardy partner

deb http://security.ubuntu.com/ubuntu hardy-security main restricted
deb-src http://security.ubuntu.com/ubuntu hardy-security main restricted
deb http://security.ubuntu.com/ubuntu hardy-security universe
deb-src http://security.ubuntu.com/ubuntu hardy-security universe
deb http://security.ubuntu.com/ubuntu hardy-security multiverse
deb-src http://security.ubuntu.com/ubuntu hardy-security multiverse
ani@WhiteRat:~$ clear

ani@WhiteRat:~$ cat /etc/apt/sources.list
#deb cdrom:[Ubuntu 8.04 _Hardy Heron_ - Release i386 (20080423)]/ hardy main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.

deb http://in.archive.ubuntu.com/ubuntu/ hardy main restricted
deb-src http://in.archive.ubuntu.com/ubuntu/ hardy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://in.archive.ubuntu.com/ubuntu/ hardy-updates main restricted
deb-src http://in.archive.ubuntu.com/ubuntu/ hardy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## universe WILL NOT receive any review or updates from the Ubuntu security
## team.
deb http://in.archive.ubuntu.com/ubuntu/ hardy universe
deb-src http://in.archive.ubuntu.com/ubuntu/ hardy universe
deb http://in.archive.ubuntu.com/ubuntu/ hardy-updates universe
deb-src http://in.archive.ubuntu.com/ubuntu/ hardy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://in.archive.ubuntu.com/ubuntu/ hardy multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ hardy multiverse
deb http://in.archive.ubuntu.com/ubuntu/ hardy-updates multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ hardy-updates multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb http://in.archive.ubuntu.com/ubuntu/ hardy-backports main restricted universe multiverse
# deb-src http://in.archive.ubuntu.com/ubuntu/ hardy-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository. This software is not part of Ubuntu, but is
## offered by Canonical and the respective vendors as a service to Ubuntu
## users.
# deb http://archive.canonical.com/ubuntu hardy partner
# deb-src http://archive.canonical.com/ubuntu hardy partner

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

johnnybravo666
July 17th, 2008, 09:33 PM
Do you have the DVD or CD version of ubuntu?

AceDip
July 17th, 2008, 09:36 PM
i have the cd.

johnnybravo666
July 17th, 2008, 09:46 PM
I don't think the CD version comes with the build-essential package. I may be wrong though. Try this.

Run
sudo gedit /etc/apt/sources.list. This will bring up the sources.list file in the text editor.

Look for a line that reads
#deb cdrom:[Ubuntu 8.04 _Hardy Heron_ - Release i386 (20080423)]/ hardy main restricted Remove the '#' from the beginning of the line.

Then save and close. Run
sudo apt-get update

Then
sudo apt-get install build-essential

This will include the packages on the CD in the package list. They should already be there though. But its worth a try if you don't have a internet connection in linux. Your best bet is to get your internet connection working in linux.

AceDip
July 17th, 2008, 10:26 PM
I don't think the CD version comes with the build-essential package. I may be wrong though. Try this.

Run
sudo gedit /etc/apt/sources.list. This will bring up the sources.list file in the text editor.

Look for a line that reads
#deb cdrom:[Ubuntu 8.04 _Hardy Heron_ - Release i386 (20080423)]/ hardy main restricted Remove the '#' from the beginning of the line.

Then save and close. Run
sudo apt-get update

Then
sudo apt-get install build-essential

This will include the packages on the CD in the package list. They should already be there though. But its worth a try if you don't have a internet connection in linux. Your best bet is to get your internet connection working in linux.
Thanks a lot man..did as u said and the thing worked..thanks again.i had put in quite a lot of time for this..anyways all is well that ends well..i was begining to get fed-up of ubuntu coz this was important..

and yeah well could you kindly explain to me wat we just did and wat had happen..

AceDip
July 17th, 2008, 10:34 PM
I would look into your sources.list file for proper repositories. Just do a gedit on /usr/apt/sources.list and show us the contents of that file.
i must also thank you era for bringing in the idea of ckecking the cources.list file without which i dont think we'd have reached the solution.

Tony Flury
July 17th, 2008, 10:51 PM
i must also thank you era for bringing in the idea of ckecking the cources.list file without which i dont think we'd have reached the solution.

Especially as loads of other people suggested it too :-) lol

Glad you got it sorted though.

johnnybravo666
July 17th, 2008, 10:59 PM
'/etc/apt/sources.list' is a list of software repositories that apt should check for packages. Basically the line that added the CD as a software repository was commented out. But once you uncommented it, the CD was added as a software repository and you could install software that was located on the CD. The 'sudo apt-get update' tells apt to update its list of packages from the repositories listed in the '/etc/apt/sources.list' file.

In case you were wondering, apt is the package management system on ubuntu.

If you have any more questions, please ask.

It's a pleasure to help. I've gotten a lot of help from these forums and other linux users in general so I like to help others where I can.

era86
July 17th, 2008, 11:41 PM
i must also thank you era for bringing in the idea of ckecking the cources.list file without which i dont think we'd have reached the solution.

Glad to have helped. Just doin what this community taught me. ;)

Don't forget to mark your thread as Solved.

AceDip
July 18th, 2008, 06:54 AM
Especially as loads of other people suggested it too :-) lol

Glad you got it sorted though.
well dude cant ignore u.you have been there since the begining..thanks a lot man.got my trust and respect back for ubuntu.

AceDip
July 18th, 2008, 07:03 AM
'/etc/apt/sources.list' is a list of software repositories that apt should check for packages. Basically the line that added the CD as a software repository was commented out. But once you uncommented it, the CD was added as a software repository and you could install software that was located on the CD. The 'sudo apt-get update' tells apt to update its list of packages from the repositories listed in the '/etc/apt/sources.list' file.

In case you were wondering, apt is the package management system on ubuntu.

If you have any more questions, please ask.

It's a pleasure to help. I've gotten a lot of help from these forums and other linux users in general so I like to help others where I can.
well then if this is the case with the cd installation then it certainly sounds quite tough for a newbie.then why does ubuntu have to be so rigid to support even the most common programming languages..they should have been pre-installed and even if not then why so technical.

dribeas
July 18th, 2008, 11:01 AM
I also want to emphasize adding the line:

return 0;

I often find this floating around in discussions. C++ standard clearly states that a function must have a return type or be marked as void. Method/function implementations must return an element of the appropiate type (sadly, g++ does not flag this as an error or even a warning with default options) with the only exception of main that must define int as return value but that is allowed not to return anything with the compiler inserting an implicit return 0.

David