help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: library problem - my own version of C++ using gcc does not link


From: Bernd Strieder
Subject: Re: library problem - my own version of C++ using gcc does not link
Date: Thu, 24 May 2007 20:07:13 +0200
User-agent: KNode/0.10.4

Hello,

Robert Heller wrote:

> At Thu, 24 May 2007 15:08:26 GMT Jim Anderson <ezjab@ieee.org> wrote:

> 
> gcc can link C++ code, but you need to give it a 'hint' that you are
> in fact linking C++ code, usually by including the -l option(s) that
> g++ would normally add:
> 
> gcc -g -o test test.o Product.o DerivedProduct.o Creator.o \
> DerivedCreator.o -lstdc++ -lc++

That is usually not enough, the linker might need special options, there
are linking passes special to C++, special startup code might be
necessary and more, all differing between platforms and compiler
releases. Just use g++, it has been working the same way for a long
time, and almost everywhere.

>> I appreciate your help but if you can shed light on why gcc
>> compiles C++ but does not link it, I'm curious to know why.

It is easy to guess from the extension, .cc,.cxx or whatever, that the
source file is C++, but guessing whether an object file is C++ is a lot
more difficult, and moreover it might require an extra linking pass
before the usual ones to first check all files to find out whether C
linking mode or C++ linking mode is necessary. So there is no
reasonable heuristic for automatically linking the right way. So it is
not done, and the user has to use the right command.

The reason to use the compiler driver for linking at all probably is,
that sometimes the same options must be given at compile and link time.
The c++ compiler might be called during linking c++ code under some
conditions. Handling those common options is easily done by making the
compiler driver (gcc or g++) also calling the linker whenever object
files are passed, or even by default, when compiling without -c. This
way a build script or a makefile needs to collect all options only
once, there is no need to manually keep compiler and linker settings
synchronized.

Bernd Strieder



reply via email to

[Prev in Thread] Current Thread [Next in Thread]