Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Mixing C with C++ Message-ID: <691@taumet.com> Date: 25 Apr 91 14:50:02 GMT References: <1991Apr22.064847.16929@cs.nott.ac.uk> <1991Apr23.133931.6716@ssd.kodak.com> <690@taumet.com> Organization: Taumetric Corporation, San Diego Lines: 29 steve@taumet.com (Stephen Clamage) writes: >You write the actual main() in its own module like this: > extern int my_main(int, char**); > main(int argc, char** argv) > { > return my_main(argc, argv); > } >Compile it with the C++ compiler, and put it in your library. Instruct >your users to write their main() with the name "my_main" instead. >Everything should just work. Oops! I forgot two very important points. 1. Unless you supply the C++ runtime library and any special startup modules (some systems provide a replacement crt0.o or equivalent), or you will have to pre-link your entire library with the C++ runtimes and supply it as a single object module. Otherwise, things may turn up missing when a user tries to link a program. 2. Most C++ implementations require steps to be done after linking. (Cfront requires "patch" or "munch", Oregon C++ requires "cdlink".) Any application with static objects requiring constructors or destructors (such as stream I/O) will require this step. You will have to experiment to see if the step can be omitted when there are no static objects. -- Steve Clamage, TauMetric Corp, steve@taumet.com