View Full Version : What is g++?
Soulstorm
Jun 14, 2005, 03:54 PM
This may sound like a newbish question, but what is g++? It is required to use this command when compiling with the teminal a c++ file.
But I haven't seen that only as a reference to a terminal command, I have also seen it somewhere else, although I can't remember where.
What is it?
cubist
Jun 14, 2005, 04:04 PM
Gnu C compiler (gcc) C++.
I think this is old terminology, you just use gcc for .c and .cpp files now.
superbovine
Jun 14, 2005, 05:42 PM
Gnu C compiler (gcc) C++.
I think this is old terminology, you just use gcc for .c and .cpp files now.
nope, doesn't that way. g++ must be used with C++ code.
-- bar.c --
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
from terminal
superbovine:cow ~/foo $ gcc bar.c -o bar
bar.c:1:20: error: iostream: No such file or directory
bar.c:3: error: parse error before 'namespace'
bar.c:3: warning: data definition has no type or storage class
bar.c: In function 'main':
bar.c:8: error: 'cout' undeclared (first use in this function)
bar.c:8: error: (Each undeclared identifier is reported only once
bar.c:8: error: for each function it appears in.)
bar.c:8: error: 'endl' undeclared (first use in this function)
superbovine:cow ~/foo $ g++ bar.c -o bar
superbovine:cow ~/foo $ ./bar
Hello World
superbovine:cow ~/foo $
slb
Jun 14, 2005, 05:52 PM
g++ is a symbolic link to gcc, IIRC.
DXoverDY
Jun 14, 2005, 06:02 PM
g++ is a symbolic link to gcc, IIRC.
correct. gcc does it all, the g++ executable is simply for backwards compatibility i believe.
Soulstorm
Jun 14, 2005, 06:09 PM
correct. gcc does it all, the g++ executable is simply for backwards compatibility i believe.
Actually, I think that pressing "gcc" will not work with c++ files.
DXoverDY
Jun 14, 2005, 06:48 PM
Actually, I think that pressing "gcc" will not work with c++ files.
works perfectly fine for me man, xcode 2.1
open terminal..
cd /usr/bin/
ls -l g++*
ls -l gcc*
notice anything similar about each?
i was wrong that they aren't symbolic links, but regardless, they're the same file. and again, my c++ files compile just fine with gcc or g++
what's even more funny is that you asked in this thread what gcc is... and now you're the expert.. lol.. :rolleyes:
AlmostThere
Jun 14, 2005, 06:55 PM
Use gcc -x c++ to compile c++ files.
g++ is simply a frontend that brings in all the stuff required to compile c++. All part of the Gnu Compiler Collection
iMeowbot
Jun 14, 2005, 06:57 PM
g++ is a symbolic link to gcc, IIRC.
No, but the real differences in g++ and gcc are very small, simply defaulting to a different architecture type (which in turn makes a very big difference in how the compiler and linker are run).
SamMiller0
Jul 1, 2005, 10:06 AM
Use gcc -x c++ to compile c++ files.
g++ is simply a frontend that brings in all the stuff required to compile c++. All part of the Gnu Compiler Collection
On the version of gcc I use (3.3.5 on Debian) you still have to link with the stdc++ library or you get linker errors.
gcc -x c++ -lstdc++ -o foo foo.cpp
Loge
Jul 4, 2005, 07:59 PM
On the version of gcc I use (3.3.5 on Debian) you still have to link with the stdc++ library or you get linker errors.
gcc -x c++ -lstdc++ -o foo foo.cpp
This is the same on Mac OS X. With g++ you don't need to remember the name of the library, which is just as well because I usually misspell it.
AlmostThere
Jul 5, 2005, 06:06 PM
On the version of gcc I use (3.3.5 on Debian) you still have to link with the stdc++ library or you get linker errors.
gcc -x c++ -lstdc++ -o foo foo.cpp
Very much so. My previous post was far from clear :(
gcc -x c++ is only for compilation and does not invoke the linker with libstdc++ (which g++ does).
Also, gcc will compile the above example as c++ anyway, if foo.cpp was renamed foo.c then -x c++ is required to override the default behaviour which is based on file extension:
gcc -c -x c++ foo.c
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.