On Fri, Dec 05, 2003 at 03:06:05PM +0100, Oliver Lange wrote:
> warning: undefined reference to `operator new(unsigned)'
> warning: undefined reference to `operator delete(void*)'
> warning: undefined reference to `vtable for 
> __cxxabiv1::__si_class_type_info'
> 
> These are calls from a C function which is using a C++ class.  What's
> the difference between GCC2 and GCC3 ? Is it a missing software
> package ?

There are two things that may help:

1. Try compiling your code with g++ instead of gcc.  If you are using
new and delete, then you are writing c++ code.

2. In your header file, try to wrap your function prototypes like the
following:

#ifdef __cplusplus
extern "C" {
#endif
int some_function(int x);
char another_function(const char* s);
#ifdef __cplusplus
}
#endif

Linking is performed a bit differently for C and C++.  Using extern "C"
tells the compiler to make C++ functions visible to C.

You really can't just declare a C++ object in C.  The C language alone
knows nothing of classes, objects, function overloading, the STL and all
the other stuff C++ adds.  When you start using those features in your
c file, you may as well rename it .cc (or .cxx or .cpp or whatever
extension you use for C++ source files).  Note that that means that you
can't just wrap your C++ classes with extern "C" and expect them to be
available to regular C.

If you have some C++ source whose functionality you wish to make
available to vanilla C, you have to write some kind of interface or
wrapper code.

Look at it this way, C++ is a *superset* of C.  You can call C functions
from C++.  But you can't call C++ code from C without writing some C++
that allows you to do that.

Hope that helps,
Matt

-- 
Matt Garman
email at: http://raw-sewage.net/index.php?file=email


--
[EMAIL PROTECTED] mailing list

Reply via email to