Please somebody let me know why, i will appreciate so much. I hate doing things that i dont know why. I will not use g++ to compile my *.cpp until i know why. Thank you.

08-19-2010

brewbuck

gcc and g++ are both wrappers around the same underlying compiler engine. They both understand C++ and can compile it. However, the linking step to produce a final executable is different for the C and C++ languages. The gcc wrapper has no knowledge of the C++-specific libraries needed to link a C++ program. Therefore, the link step will fail with some obscure error messages.

Unless you are compiling a truly standalone C++ program that doesn't use any C++ features which are provided by runtime support (i.e., no exceptions, no C++ standard libraries, no nothing, really), you cannot use gcc to link a C++ program.

However, you may be able to compile with gcc and then link with g++, though I have no idea why you'd want to:

Code:

$ XXXXXXXXXX
$ XXXXXXXXXX

I do not recommend the above. In fact, it's so disgusting that I've blanked it out because you'd probably take it and run with it.

Quote:

I will not use g++ to compile my *.cpp until i know why. Thank you.

This is simply baffling. The default assumption should be to use the right tool for the job. There's being curious, and there's being deliberately obstinate.

08-19-2010

namduong

thanks brewbuck, so gcc doesn't have c++ libraries and it can't understand anything that belongs to std namespace.

I think i was confused between "gcc" - the tool to compile and link C, and "GCC" - GNU Compiler Collection; ...

so g++ came with GCC when i installed GCC on my server. I was wondering where the hell is that g++ came from.

thanks for your help, i will use g++ to compile my works from now.

08-19-2010

kermit

GCC used to stand for Gnu C Compiler. Although it stands for Gnu Compiler Collection now, the name that invokes the C compiler stuck. On a traditional Unix system, would you expect that invoking cc on a Fortran source file would be particularly useful? Why then would you want to use the C compiler on a C++ file? Use g++ - it is analogous to CC on other Unix systems.

08-19-2010

namduong

Quote:

Originally Posted by kermit

GCC used to stand for Gnu C Compiler. Although it stands for Gnu Compiler Collection now, the name that invokes the C compiler stuck. On a traditional Unix system, would you expect that invoking cc on a Fortran source file would be particularly useful? Why then would you want to use the C compiler on a C++ file? Use g++ - it is analogous to CC on other Unix systems.

yeah i know, i though "GCC" and "gcc" are the same thing. Thanks man.

I love this forum people response so fast.

08-19-2010

Babkockdood

It's because this is an easy question to respond to. G++ is a C++ compiler. GCC is a C compiler.