tags:

views:

426

answers:

5

Dear all,

I have a problem with simple c++ programs...

I would like to install a program, but always have the error like "c++ compiler is unable to create executables"...

Now I tried to compile a simple "hello world" program, but I get errors as I would if I compile a c++ program with a c compiler ("`cout' undeclared"... although I included iostream)...

Now I am not sure, if g++ does not work on my machine?

Does anyone know about how to fix this problem?

Thank you very much in advance...
Chris


Added In response to Pax's answer:

Well, I think, my code is okay, I can compile it on another machine, and I use the namespace std...

So, it's not possible, that the configuration of g++ is mismatched or something like that...?

A: 

thanx for your help!

Well, I think, my code is okay, I can compile it on another machine, and I use the namespace std...

So, its not possible, that the configuration of g++ is mismatched or something like that...?

thank you again, Chris

@Chris, this should be put as a comment to my answer otherwise I'm unlikely to be notified of it. However, since my meagre effort didn't help (and that's all I had), I'll delete the answer. Hopefully someone else can help out.
paxdiablo
And you should then delete this 'answer' since it isn't really and will likely be voted down :-)
paxdiablo
+3  A: 

Did you try calling g++ directly? If you run:

g++

and it isn't installed, you should get the usual invalid command message, but if it is installed you should see something like:

g++: no input files

If you see that, then try running this:

g++ -o output-file input-file

replacing output-file and input-file with whatever. You can specify multiple input source files.

If g++ is installed, that should work. Normally you don't need to configure anything. If it doesn't work, then chances are its simply not installed.

On a debian-based machine you should simply be able to apt-get install g++ should be similarly easy on other systems.

Dan
Yes, most often the problem is calling gcc -- which can itself use g++ but which doesn't set up a C++ environment, doesn't link to the C++ standard lib, and doesn't search teh C++ headers -- instead of g++ which handles a lot of things in the background.
Max Lybbert
+1  A: 

The biggest help when trying to diagnose a problem when running configure is to look at config.log. The last error shown in that file is what caused the message you're seeing. I've seen plenty of instances where configure has output one error, but the log shows that the problem is with a completely different component (e.g., trying to use a library before it was checked for).

Ignacio Vazquez-Abrams
A: 

"`cout' undeclared" most likely means a bug in your source.

Please either show us your source, or compile and run this:

#include <iostream>
int main() { std::cout << "Hello" << std::endl; }

If above code does not compile (using e.g. "g++ t.cc"), show complete error message, and output from "g++ -v".

If it does compile and run (which is likely), then there is nothing wrong with your g++, and the problem is with your source. The fact that your source compiles on a different machine means nothing -- your code could still be badly broken.

A: 

Outside of calling the "wrong" compiler (using gcc instead of g++, see answer by Dan) it is possible but unusual to have gcc correctly built but g++ incorrectly built.

It is also possible that your system came with just gcc, and somebody installed g++ later into a different directory. And if so, it is possible that the newer g++ is incorrectly set up.

Try running the commands

which gcc
which c++

From the command line. If gcc is in, say, /usr/bin but g++ is in /usr/local/bin, then you may have this problem. You can also ask to see if the versions match:

gcc --version
g++ --version
Max Lybbert