* Laurence Finston <[EMAIL PROTECTED]> [2008-11-28 15:48:02 +0100] | > You need to do it to interface to any library written in C (such as | > the standard C library for example). For example, try the following | > C++ code with and without 'extern "C"'. Without it, you won't be able | > to link. Fortunately, all your system headers already provide you with | > 'extern "C"' by default. | > | > extern "C" void exit(int); | > int main() | > { | > exit(0); | > } | | Thank you for the information. However, I was able to compile and link | with and without 'extern "C"' using GCC 3.3.3 on a system running | GNU/Linux (SuSE). I couldn't link when I compiled with `g++' and tried | to link with `gcc', but the error didn't seem to have anything to do with | the problem under discussion: | | mangle.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' | | Am I missing something here? Clearly, `extern "C"' has a purpose, or it | wouldn't exist. Does GCC do something special, or have I done something | wrong?
I wrote "this C++ code". It means that you must compile it with g++ (otherwise it is valid C code), as well as link it with g++ (without deriving too much, let me just say that g++ called in link mode does a bit more than linking -- it takes care of the exceptions, constructors and destructors as well through another program called collect2). | It seems to me that if a compiler doesn't mangle any "unqualified" names, | i.e., ones declared outside of a namespace or a class, it should be possible to link | with the object file in which they are defined without the linker having to | do anything special. However, it's been a long time since I read | anything about this subject and this may be naive. The linker does nothing special wrt mangled names. Only the compiler does. _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison