Can gcc be installed but g ++ doesn't work?

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

I would like to install the program, but I always have an error like "C ++ compiler cannot create executable files" ...

Now I have tried to compile a simple "hello world" program, but I am getting errors as if I were compiling a C ++ program with an ac compiler ("cout" undeclared "... although I included iostream) ...

Now I'm not sure if g ++ isn't working on my machine?

Does anyone know how to fix this problem?

Thank you in advance ...
Chris


Added In response to Pax's answer:

Well I think my code is fine, I can compile it on a different machine and I use the std namespace ...

So, isn't it possible that the g ++ config is incompatible or something like that ...?

+1


source to share


5 answers


Have you tried calling g ++ directly? If you run:

g++

      

and it is not 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 this, try running this:



g++ -o output-file input-file

      

replace the output file and input file with whatever. You can specify multiple source source files.

If g ++ is installed, this should work. You usually don't need to configure anything. If that doesn't work, then the odds of it just aren't established.

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

+3


source


The biggest help when trying to diagnose a problem when running configure is to look at the config.log. The last error listed in this file triggers the message you see. I've seen many cases where configure prints one error, but the log shows that the problem is with a completely different component (for example, trying to use a library before it has been tested).



+1


source


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

Please either show us your source or compile it and run:

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

      

If the above code doesn't compile (using for example "g++ t.cc"

) show the full error message and output from "g++ -v"

.

If it compiles and runs (which is quite likely), then there is nothing wrong with your g ++ and the problem is with your source. The fact that your source is compiled on a different machine doesn't mean anything - your code can still be badly damaged.

0


source


Outside of calling the "wrong" compiler (using gcc instead of g ++ see Dan's answer) it is possible , but unusual, for gcc to build correctly, but g ++ to build incorrectly.

It is also possible that your system only comes with gcc and someone installed g ++ later in a different directory. And if so, it is possible that the new g ++ is misconfigured.

Try 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 might have this problem. You can also ask if the versions match:

gcc --version
g++ --version

      

0


source


Install the package required for building on your computer and try again. For me this issue was resolved.

sudo apt-get install build-essential

      

0


source







All Articles