linking with binaries built with other compilers

John (Eljay) Love-Jensen eljay@adobe.com
Wed May 9 13:36:00 GMT 2007


Hi MC,

>On the Windows XP platform, is it possible to have our application built with gcc, although some of the third party libraries we are linking with were built with Intel C++ or Visual C++?

C++?  No.

C?  Yes.

Is the C++ is insulated by an opaque C thunk API?  Then yes.

>Will the application link and execute?

If using a C ABI, then yes.

Caveats...

C++ exceptions cannot pass over the C ABI barrier.  The C thunk API has to catch all internal exceptions, and transmorgify them into error return codes.

RTTI cannot be used between the different C++ platforms.

If you have a std::string in Visual C++ land, you cannot use that object as-is in GCC C++ land.  And vice versa.

If you have a std::vector in Visual C++ land, you cannot use that container object as-is in GCC C++ land.  And vice versa.

Structures (plain old structures) may have different memory layout (different packing, alignment, padding) in Visual C++ land and GCC C++ land.  Care must be taken.

Visual C++ I/O streams and GCC C++ I/O streams are independent.

You may say "This is a terrible state of affairs!"  The C++ standards committee proposed a Standard C++ ABI, but the compiler vendors (who are also represented on the committee) were not very keen on the idea.  Effectively, the C++ ABI issue has been deferred for now.  Maybe it will be standardized at some point in the future, say C++201x or C++202x.  In the meantime, I'm not holding my breath.

>From my previous posting <http://gcc.gnu.org/ml/gcc-help/2004-06/msg00229.html>...

What would C++ ABI standardization compliance provide? All C++ names mangled the same way. Exception handling handled the same way. RTTI handled the same way (including POD types). All stacks (on a given architecture/OS) structured the same way. All calling conventions the same. All C++ infrastructure the same (such as initializations of statics), handled the same way. Anonymous namespaces would probably be handled the same way (and not pollute the TOC with random munged names different from compile-to-compile!). Instantiated templates would be compiler agnostic. Different pre-built binary libraries (.a, .so, .shlib, .library, .dll, .lib, whatever) would be compiler agnostic. All intrusive (in the shared header files) extensions would be strongly discouraged by the developer community at large. And that's probably just the tip of the iceberg.

HTH,
--Eljay



More information about the Gcc-help mailing list