Can I use gcc to compile C++ program? Is there any difference with using g++ instead?
On an exisitng system, I type “man g++”, the system returns “no manual entry for g++”. But it has gcc installed. Is that possible to install g++ from existing gcc library directly; or I have to download g++ instead?
You can use
gccto compile C++ programs as long as you set the proper flags and/or use the right extensions on your source-files (i.e., use.cpp), but that’s only if the C++ development tools, such as libstdc++ have been installed … and that typically means thatg++is available as well. So if you don’t have the C++ development tools and libraries installed, then no, you’re not going to be able to compile C++ files, especially if you start using elements from the STL, etc.That being said, if you restricted your C++ source-code to a strict C-subset of the language, then I don’t see why it wouldn’t compile … but that would defeat the whole point of using C++ in the first place … it would just be a C file with a
.cppextension 🙂If you are on Linux, then installing g++ is fairly straight-forward. Simply search the repository for g++ using
apt-get,yum, or some other package manager, and it should come up as a nice pre-compiled binary, along with all it’s dependencies. If you are on OSX, then it comes with the Xcode developer tools. If you are on Windows, then you can use MinGW-w64, and again, that comes as a pre-compiled binary for x86_64, or you could use the version that comes with Cygwin (you didn’t mention your platform, so it’s possible you could be running Cywin on Windows). For that, just use the Cygwin package manager again.