Mail Archives: djgpp/2002/04/05/05:45:10
deckerben <deckerben AT freenet DOT de> wrote:
> Thanks for the suggestions.
> I pretty much knew about changing the compiler option by hand. But not every
> package is written in C++ and sometimes they are written in both.
That's not a problem. GCC is clever enough to know how to compile
C and C++ sources, both using the gcc or g++ driver. The only point where
it *really* makes a difference is the linking stage. If there are any
C++ objects involved, you will have to use g++ for linking .o files.
That's why the really good makefiles out there (including the default
setup of GNU make) use independent, configurable names for the C++ and
C compilers, like CC and CXX. CXX will default to $(CC), but you can
override that. They also have a separate variable, LD, which points
to the command to be used as the linker. LD=$(CXX) will usually take
care of all your problems.
> I was hoping for a way that DJGPP could see the difference and adapt itself
> 'on-the-fly' as they say.
It can't. .o files don't bear a stamp that would show whether they
were made by compiling C or C++ files (or Fortran, or Pascal, or
straight from assembly, or ...).
> Some compilers know, for instance, that they should automaticly try a full
> C++ convention with source files that have the .cpp file extension, and an
> ANSI C convention when they end with .c
GCC does that. But the moment you separate compilation into .o files
and linking, most of those compiles will fail, too. In GCC, e.g.
gcc -o myprog.exe myprog.cpp
will work. But
gcc -c myprog.cpp
gcc -o myprog.exe myprog.o
won't.
> But my DJGPP installation was trying to compile a C++ file only using
> default C libraries.
No. It was trying to *link* it using C libraries. There's an important
difference between compilation and linking you're missing.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -