# Can Modula-3 code call C++ and vice-versa?

There is no problem to call C++ functions declared as extern C. You must use a C++ aware linker (e.g. the C++ compiler). A complete example of M3 calling C++ objects, which in turn call M3 callbacks, is available in the sgml library.

On some platforms, a call to get the static variables constructors called may be required:

From: gwyant@cloyd.East.Sun.COM (Geoffrey Wyant - Sun Microsystems Labs BOS)

You must use your C++ compiler as the linker, rather than /bin/cc or /bin/ld.

You need to call the function '_main'. The easiest way to do this is to have the following set of interfaces and implementations:

            INTERFACE CXXMain;
              <*EXTERN "_main"*> CxxMain;
            END CXXMain;

            MODULE CXXMain;
            BEGIN
              CxxMain();
            END;

and then import CXXMain into your M3 main module. This will ensure that the C++ function _main gets called.