A query

Rupert Wood me@rupey.net
Tue Jan 15 01:58:00 GMT 2002


Jaya_Kumari wrote:

> I wanted to know if there is an option with g++ compiler where I can
> compile the C files,and the compiler treats these files as C files
> and not C++ files.

Place '-x c' before any C filenames on the command line (see "g++
--help"). However, unless you're linking too, there is no difference
between 'gcc' and 'g++ -x c'.

> I have another query whether in a makefile whether i can use gcc
> compiler to compile C files and g++ compiler to compile C++ file

Yes; it may even happen automatically depending on the default rules of
your version of make (see its manpage). You may need to set environment
variables

    CC=gcc
    CXX=g++

or similar, e.g. Solaris make uses 'CCC' instead of 'CXX'. See the
documentation with your version of make.

If you're creating compilated build systems or need cross-platform
support then you may wish to investigate the GNU projects autoconf and
automake for makefile generation.

> and whether it is possible to link the object files of C files and
> C++ files.

Yes, provided you declare any C symbols 'extern "C"' in the C++ source
to turn of the C++ name-mangling scheme used for function overloads,
classes, etc. You should link with g++ rather than gcc.

Rup.



More information about the Gcc-help mailing list