Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC vs MS C++ compiler for maintaining API backwards binary compatibility

Tags:

I came from the Linux world and know a lot of articles about maintaining backwards binary compatibility (BC) of a dynamic library API written in C++ language. One of them is "Policies/Binary Compatibility Issues With C++" based on the Itanium C++ ABI, which is used by the GCC compiler. But I can't find anything similar for the Microsoft C++ compiler (from MSVC).

I understand that most of the techniques are applicable to the MS C++ compiler and I would like to discover compiler-specific issues related to ABI differences (v-table layout, mangling, etc.)

So, my questions are the following:

  • Do you know any differences between MS C++ and GCC compilers when maintaining BC?
  • Where can I find information about MS C++ ABI or about maintaining BC of API in Windows?

Any related information will be highly appreciated.
Thanks a lot for your help!

like image 430
linuxbuild Avatar asked Jan 24 '11 13:01

linuxbuild


People also ask

What is binary compatibility c++?

A library is binary compatible, if a program linked dynamically to a former version of the library continues running with newer versions of the library without the need to recompile.

Is Visual Studio better than GCC?

In the question“What are the easiest to use C++ compilers and IDEs?” Microsoft Visual C++ is ranked 2nd while GCC is ranked 3rd. The most important reason people chose Microsoft Visual C++ is: To get C++ running on a build machine, just copy the VC bin, and all the headers/libraries you'll need.

Is Msvc a good compiler?

Microsoft Visual Studio is a good compiler for developing Windows applications. Although Visual Studio presents a ton of choices to the user when first starting out (for instance, there are a lot of different project types), the amount of choice gives a good idea of the overall scope of this tool.

Can you use GCC with Visual Studio?

In addition to the Microsoft Visual C++ compiler that many of you are likely familiar with, Visual Studio 2017 also supports Clang, GCC, and other compilers when targeting certain platforms.


2 Answers

First of all these policies are general and not refer to gcc only. For example: private/public mark in functions is something specific to MSVC and not gcc.

So basically these rules are fully applicable to MSVC and general compiler as well.

But...

You should remember:

  1. GCC/C++ keeps its ABI stable since 3.4 release and it is about 7 years (since 2004) while MSVC breaks its ABI every major release: MSVC8 (2005), MSVC9 (2008), MSVC10 (2010) are not compatible with each other.
  2. Some frequently flags used with MSVC can break ABI as well (like Exceptions model)
  3. MSVC has incompatible run-times for Debug and Release modes.

So yes you can use these rules, but as in usual case of MSVC it has much more quirks.

See also "Some thoughts on binary compatibility" and Qt keeps they ABI stable with MSVC as well.

Note I have some experience with this as I follow these rules in CppCMS

like image 173
Artyom Avatar answered Sep 23 '22 12:09

Artyom


On Windows, you basically have 2 options for long term binary compatibility:

  1. COM
  2. mimicking COM

Check out my post here. There you'll see a way to create DLLs and access DLLs in a binary compatible way across different compilers and compiler versions.

C++ DLL plugin interface

like image 41
Tobias Langner Avatar answered Sep 26 '22 12:09

Tobias Langner