Please explain the C++ ABI

发布时间:2025-11-26 11:31

'Confirmation'用'Please confirm the meeting details'请求确认 #生活技巧# #职场沟通技巧# #商务英语口语#

This question shows research effort; it is useful and clear

21

Save this question.

Show activity on this post.

The common explanation for not fixing some issues with C++ is that it would break the ABI and require recompilation, but on the other hand I encounter statements like this:

Honestly, this is true for pretty much all C++ non-POD types, not just exceptions. It is possible to use C++ objects across library boundaries but generally only so long as all of the code is compiled and linked using the same tools and standard libraries. This is why, for example, there are boost binaries for all of the major versions of MSVC.

(from this SO answer)

So does C++ have a stable ABI or not?

If it does, can I mix and match executables and libraries compiled with different toolsets on the same platform (for example VC++ and GCC on Windows)? And if it does not, is there any way to do that?

And more importantly, if there is no stable ABI in C++, why are people so concerned about breaking it?

asked Jun 4, 2021 at 14:28

Alex O's user avatar

6

This answer is useful

19

Save this answer.

Show activity on this post.

Although the C++ Standard doesn't prescribe any ABI, some actual implementations try hard to preserve ABI compatibility between versions of the toolchain. E.g. with GCC 4.x, it was possible to use a library linked against an older version of libstdc++, from a program that's compiled by a newer toolchain with a newer libstdc++. The older versions of the symbols expected by the library are provided by the newer libstdc++.so, and layouts of the classes defined in the C++ Standard Library are the same.

But when C++11 introduced the new requirements to std::string and std::list, these couldn't be implemented in libstdc++ without changing the layout of these classes. This means that, if you don't use the _GLIBCXX_USE_CXX11_ABI=0 kludge with GCC 5 and higher, you can't pass e.g. std::string objects between a GCC4-compiled library and a GCC5-compiled program. So the ABI was broken.

Some C++ implementations don't try that hard to have compatible ABI: e.g. MSVC++ doesn't provide such compatibility between major compiler releases (see this question), so one has to provide different versions of library to use with different versions of MSVC++.

So, in general, you can't mix and match libraries and executables compiled with different versions even of the same toolchain.

answered Jun 4, 2021 at 22:40

Ruslan's user avatar

2 Comments

To be clear, as std::string is the default string class in C++, they broke compatibility with older C++ versions. This was the time to remove all old/bad/deprecated stuff from the language & std (imho).

2022-06-08T09:43:31.217Z+00:00

Note that MSVC has had ABI compatibility since 2015 (the linked answer is from 2009).

2023-04-03T19:30:21.577Z+00:00

This answer is useful

0

Save this answer.

Show activity on this post.

C++ does not have an ABI standard as of yet. They are attempts to have it in the standard; You can read following it explains it in details:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2028r0.pdf

NathanOliver's user avatar

NathanOliver

183k29 gold badges323 silver badges439 bronze badges

answered Jun 4, 2021 at 14:35

Abdurrahim's user avatar

Abdurrahim

2,1941 gold badge18 silver badges24 bronze badges

2 Comments

My understanding of that paper's position is that there is a de facto ABI standard, that there has been since C++11, and that any changes to the C++ standard that would break ABI are routinely vetoed by implementers.

2021-06-04T15:15:47.963Z+00:00

Well it is a defacto standard. It does not define how assemblies/modules to be used. Otherwise we would have a standard about using lets say C++XY abi, from lets say C++23. We have such layers well defined for C for example (extern "C") why not have a (extern "C++XY"). This example is not good, but there needs to be something like that, maybe a compile/linker option,

2021-06-04T15:25:04.837Z+00:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

网址:Please explain the C++ ABI https://klqsh.com/news/view/291123

相关内容

EXPLAIN Synonym: List of 18 Synonyms for Explain with Useful Examples
Explain plan
Android Maui app “Doesn't support required ABI”
Monetary policy and the krone exchange rate
Print the Fibonacci sequence Python
NCERT Solutions for Class 10 Science Chapter 11: The Human Eye and Colourful World
Relations in the Gene Ontology
Unit4 The art of having fun单元内容解析及练习(含答案)外研版(2024)七年级英语下册
Vacation Packages and Deals
托福口语话题电影人物解析

随便看看