Re: Problem linking object with extern "C"

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

 



Andrew Hardy wrote:
> It is my understanding that this will enable the linker to assosiate
> function calls in the 'C' compiled object file with the 'C' functions in
> the 'C++' compiled object file.

It really just turns off "name mangling" which provides for type safe
linking.  If it is off then you have C linkage.  If on, then C++
linkage.  It does not prevent you from using C++ features which
require the C++ support library.  Some people have had success using a
limited subset of C++ to do that however.

> If I remove any C++ features from the function definitions linking
> succeeds, but as soon as I introduce any C++ feature to the function body,
> then compile succeeds, but linking fails.  I undewrstood the idea of this
> feature was to allow C++ code to provide a 'C' interface for C code to call
> and pass agruments!

Actually the idea is to allow a C++ program to link in C libraries.
There are all of these nifty C libraries and this provides a way to
use them from a C++ program.  The reverse of trying to use a C++
library in a C program is a stretch.

Think of static global initializers such as "X x;" which has a
constructor.  The C++ startup initializes that variable.  But a C
startup does not have any code to do that and it won't get
initialized.  So you can easily link in C libraries into your C++
program.  But a library of C++ code has expectations beyond C which
are not met by the C startup.

Bob

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux