gnu/13525: gcc fails load against library with both C++ and C modules

Gerald Pfeifer gerald at
Thu May 22 09:40:30 PDT 2003

On Wed, 21 May 2003, Keith Bostic wrote:
> Your analysis misses the point I tried to make -- if you write
> a C program, which only uses C library modules, why should a C++
> compiler be needed?

You don't actually need the C++ _compiler_, but C++ code generated by GCC
needs to link in some support library.

This can be accomplished by explicitly specifying this library or by
using the g++ driver instead of the gcc to perform the final linkage.

> Neither the C code you wrote, nor the C library modules you loaded,
> should have "used any C++ library routines (directly or indirectly)" --
> why does the act of loading against a library that contains both C and
> C++ modules, suddenly require use of a C++ compiler?

You don't need a C++ compiler, but the C++ modules require you to link
with libstdc++ or (as of GCC 3.0) libsupc++.

In fact, GCC 3 switch to a minimal library like libsupc++ also to help
users like you who don't really need a full C++ library.

> There shouldn't be any "additional libraries" required -- it's
> a program written entirely in C, it never loaded a C++ anything,
> why would there be any need for additional C++ libraries!?

The (nice) example program added to the PR by someone else used iostream,
so in that case one explictly needs full C++ libraries, but even if we
remove that use of iostream, current GCCs will complain about


missing.  That is, the problem you were seeing gut improved, indeed, and
if you just add -lsupc++ to your linker command, everything is fine (and
you can indeed link using gcc).

> I mean, it's probably that there's something that's getting magically
> loaded out of the library, just because it exists in the library, but my
> point is there's no reason for that to happen that I can think of.

Intuitively I agree with you, but would you mind raising this issue on
the gcc at list where you can reach those GCC developers who
have more in depth knowledge of that?

(This issue is not FreeBSD-specific, as has also been observed by other
committers, that's why I have closed the PR now.)


More information about the freebsd-bugs mailing list