Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!keele!nott-cs!gas From: gas@cs.nott.ac.uk (Alan Shepherd) Newsgroups: comp.lang.c++ Subject: Mixing C with C++ Message-ID: <1991Apr22.064847.16929@cs.nott.ac.uk> Date: 22 Apr 91 06:48:47 GMT Reply-To: gas@cs.nott.ac.uk () Organization: Nottingham University Lines: 26 About a week ago I posted an article asking for help with a problem I was having with making C++ functions (not methods) callable from C++. I've had quite a response so I thought other people might be interested in the necessary details. The first thing to do is to declare your C++ function to have C linkage (even though you compile it with C++) e.g. extern "C" void aC++Fn(); void aC++Fn() { cout << "A C++ Function" << endl; } This is the easy bit. The second step involves linking using C++ and not C. Most of my replies pointed this out, but I had done this and still encountered problems (sorry for not pointing this out before). The crucial step is that the file with main() needs to be compiled using C++ even if it is in a c file. Thanks to those people who pointed this out. I felt a bit of an idiot when I realised the solution, but several of my replies missed this too, so I don't feel quite so bad....:-) Alan Shepherd