There are a number of different ways to invoke gcc
with regard to
compiling different languages. The most obvious is to call the binary
responsible for that language; g++
for C++, g77
for
Fortran source files etc..
However, since all of these languages are integrated into gcc
, it is
possible to simply call gcc
along with a number of flags telling it
what language is being used. There are two things you'll need to be
aware of: linking with the correct library for that language using the
-l
option, and supplying gcc
with the correct language
using the -x
flag.
For example, invoking
$ gcc -lg++ -x c++ main.cpp
is exactly the same as calling
$ g++ main.cpp
for a C++ source file named main.cpp
. However, although you
can use the former, the latter is much easier to look at. The former
just says "use the library libg++.so
, and tell gcc
that
the source file passed in is a C++ file".
However, we'll not consider supplying any information regarding language
options or correct libraries to be passed to gcc
(other than for
Objective C); rather, we'll call the files directly, like
g++
for C++ source files, gcj
for Java sources
etc..