It depends on what exactly you changed in the makefile. gcc / g++ is really just a frontend program that calls the actual compiler and / or linker based on the parameters you give it.
If you call the compiler like gcc :
- it will compile as C or C ++ based on the file extension (
.c or .cc / .cpp ); - it will bind like C, i.e. it will not pull out C ++ libraries unless you specifically add additional arguments for this.
If you call the compiler like g++ :
- it will compile as C ++ regardless of whether the file extension is
.c or .cc / .cpp ; - it will be referenced as C ++, i.e. automatically pull out standard C ++ libraries.
(see the corresponding bit of the GCC documentation ).
Here is a simple program that determines if it has been compiled as C or C ++.
(It uses the fact that the character constant is int in C or char in C ++. sizeof(char) by definition 1; sizeof(int) will usually be larger - if only you use an obscure platform s> = 16-bit bytes, which you probably aren't.)
I named it test.c and copied it as test.cc :
$ cat test.c #include <stdio.h> int main(void) { printf("I was compiled as %s!\n", sizeof('a') == 1 ? "C++" : "C"); return 0; } $ cp test.c test.cc $
Compiling and binding test.c using gcc and test.cc using g++ works as expected:
$ gcc -o test test.c $ ./test I was compiled as C! $ g++ -o test test.cc $ ./test I was compiled as C++! $
Compiling and linking test.cc with gcc does not work: it compiles the code as C ++, because the file ends in .cc , but does not work at the link stage:
$ gcc -o test test.cc /tmp/ccyb1he5.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status $
which we can prove by separately compiling with gcc and contacting g++ (to pull into the necessary libraries):
$ gcc -c test.cc $ g++ -o test test.o $ ./test I was compiled as C++! $
... gcc compiled the code as C ++, not C, because it had the extension .cc .
While g++ does not compile .c files like regular C:
$ g++ -o test test.c $ ./test I was compiled as C++! $