Tech Support Forum banner
Status
Not open for further replies.
1 - 11 of 11 Posts

·
Registered Member
Joined
·
236 Posts
Discussion Starter · #1 ·
I got the gcc GNU compiler for C++ (among other languages) for Ubuntu, as C++ isn't working, and I want to figure out how I can fix it, so if anyone would be willing, please answer one of these two questions.

1: How does one install and configure gcc (I've read their tutorial, but I just don't get it (I'm a Linux 'newb' as some would say))

2: If no one can figure that out, why is it that my C++, well, everything, can't even find any libraries, not even the ones I know for a fact are on my computer.

Answering both would be preferred, but it's all up to you.

Thank you
-Crockeo
 

·
Alternative Computing, Moderator
Joined
·
2,754 Posts
It works fine on Ubuntu 10.10 on my laptop.
The gcc compiler for c++ is C++ not gcc ( C only)

Example (hello.world in c++)
// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}

The above file can be called hello.c ( even though in c++)
it is compiled with

c++ hello.c -o helloworld

Standard c++ libraries are in the package libstdc++
Make sure these are installed post back what you are trying to
do as I think are have invoked gcc instead of c++ to compile.
 

·
Registered Member
Joined
·
236 Posts
Discussion Starter · #4 ·
Two things:

1, I tried to just save it as a .c file and it doesn't work.

2, I think this is because I couldn't get gcc installed on my computer correctly. It's not that there's a specific error, it's just that I'm not too familiar with Linux, therefor unable to install it.
 

·
Emeritus
Joined
·
1,131 Posts
How do you know "C++" isn't working? It would help to know what packages you installed, what libraries are to be used in your program and what command(s) you are executing to compile the source code. A good description of specific actions you performed, the expected results and actual results would make understanding your situation much easier.

The file extension is just that, a file extension. What matters is what's contained in the text files (although you should generally use .cpp for C++ files, .c for C files, .h for headers, etc).

2: If no one can figure that out, why is it that my C++, well, everything, can't even find any libraries, not even the ones I know for a fact are on my computer.
What specifically makes you say the libraries are not being found?
 

·
Registered Member
Joined
·
236 Posts
Discussion Starter · #6 ·
Thank you shuuhen for your reply, I hope we can get this solved soon.

Here is my exact code, it's just a simple "Hello world!" program to see if it would work.

Code:
#include <iostream>
using namespace std;

int main()
{
cout << "Hello world!";
char response;
cin >> response;
}
The output should be:

Code:
Hello world!
But it wont compile as the '#include <iostream>', 'using namepsace std;', 'cout << "Hello world!";', and 'cin >> response;' give me errors. Everything is because the the inability to load the iostream library.
 

·
Emeritus
Joined
·
1,131 Posts
That should compile fine with g++. Could you list the specific errors? Also, to verify, are you compiling with
Code:
g++ hello.cpp -o hello
Could you post the output of
Code:
g++ --version
Hopefully the errors will indicate what is not installed or configured correctly.
 

·
Alternative Computing, Moderator
Joined
·
2,754 Posts
I think you are trying to compile C++ plus code with gcc which is a C compiler.
Either use c++ or g++ to compile.

In my example I named the c++ code just .c but naimg in .cpp is a better extension although in linux you use "+" as a legal name in a file.


#Include <iostream> is a c++ header so if you use gcc to compile the header #include <iostream> is not part of the C library and will output an error message.

Please post the exact command string that you are using to compile.
 

·
Registered Member
Joined
·
236 Posts
Discussion Starter · #9 ·
I'm not using a command, I'm doing it through the Netbeans IDE. As I previously said, I don't have g++ or anything like that working, so I'm just using the standard gcc compiler that game with my version of Ubuntu. This topic is about getting a C++ compiler working, which I am unable to do.
 

·
Alternative Computing, Moderator
Joined
·
2,754 Posts
I'm not using a command, I'm doing it through the Netbeans IDE. As I previously said, I don't have g++ or anything like that working, so I'm just using the standard gcc compiler that game with my version of Ubuntu. This topic is about getting a C++ compiler working, which I am unable to do.
IDE or command line you cannot compile C++ programs without a C++ compiler.
The gcc compiler compile C only as stated in post2.

Start synaptic and install g++ which will install the c++ library, then to check thats its installed post the output of

g++ -v

You should see output similar to the following from my laptop running
Ubuntu 10.04

[email protected]:~$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
 

·
Emeritus
Joined
·
1,131 Posts
It is still important to have the exact errors, especially since you are using an IDE. The IDE can report errors from the compiler or its own issues.

It sounds like you are saying g++ is not installed. Go into your package management system and install some version of g++. Any of the 4.x versions should be fine, but generally newer is better.

You can also use the command line to install g++
Code:
sudo apt-get install g++
After installing g++, try compiling and let us know what exact errors you get.
 
1 - 11 of 11 Posts
Status
Not open for further replies.
Top