[LC++]Windows can use cpp in c code but in linux ?? I dont know how .

Jack Lloyd lloyd at acm.jhu.edu
Thu Sep 30 22:15:02 UTC 2004


On Thu, Sep 30, 2004 at 05:26:21PM +0530, Sarvex Jatasra wrote:
> The compiler for C++ on Linux is called g++.
> To compile the C++ code you have to invoke the g++ and not gcc.
> "gcc" is used for compiling C code.
> 
> In windows you can compile C/C++ code using cl.exe/bcc32.exe and it
> calls the compiler based on  the file extension. In linux you have to
> call g++ and gcc separately (this is recommended process, you can also
> use g++ to compile C code)

To clarify a bit: You can compile C++ with 'gcc' fine, you just can't link
using gcc. That's because when linking, gcc doesn't know the link in the C++
support libraries.

If you compile all the programs on the command line using gcc, it actually
works:

  gcc file1.cpp file2.c

because in that case gcc knows that file1.cpp is being compiled as C++, so
libsupc++ needs to be linked in. In the OP's case, GCC couldn't tell that was
happening (because of the use of a static library), so the needed support code
was not linked in.

-Jack




More information about the tuxCPProgramming mailing list