Table of Contents
What is C ABI?
Why does C ABI affect compatibility?
In what circumstances do you need to pay special attention to ABI?
How to view or control C ABI?
Home Backend Development C++ Understanding the C ABI

Understanding the C ABI

Jul 24, 2025 am 01:23 AM
c++ abi

C ABI is the underlying rules that the compiler follows when generating binary code, which determines mechanisms such as function calls, object layout, name adaptation and other mechanisms; 1. It ensures that different compilation units interact correctly, 2. Different compilers or versions may adopt different ABIs, affecting dynamic library links, STL transfers, virtual function calls, etc. 3. Cross-platform development, long-term system maintenance, third-party library use and other scenarios need to pay special attention to ABI consistency, 4. The ABI can be controlled through macro definitions and compilation options, and use tools to view the symbol table to judge consistency.

Understanding the C ABI

C ABI (Application Binary Interface) is a set of rules that the compiler follows when generating binary code, which determines the function call method, object layout, name mangling, exception handling mechanism, etc. Understanding it is very critical for those who develop high-performance or cross-platform projects, especially when doing dynamic library compatibility, system-level debugging, or compiler development.

Understanding the C ABI

What is C ABI?

Simply put, ABI is a set of underlying specifications that ensure that different compilation units can interact correctly. For example, if you write a class, use its objects in another file, or call a function in a dynamic link library, the ABI is coordinating these details. If the ABI used by the two modules is inconsistent, there may be problems such as crashes, call errors or even unlinkable.

Unlike API (application program interface), ABI is more underlying, focusing on how compiled machine code works. For example:

Understanding the C ABI
  • How to pass function parameters (register or stack)
  • The order of the class member variables
  • Structure of virtual function table
  • How to spread an exception
  • Name adaptation format

These are not what programmers face directly, but they have a huge impact in some scenarios.

Why does C ABI affect compatibility?

The C language itself does not specify the specific implementation of ABI, which means that different compilers (such as GCC, Clang, MSVC) and even different versions of the same compiler may adopt different ABI rules. This difference can lead to the following problems:

Understanding the C ABI
  • Dynamic library and main program cannot be linked normally
  • STL containers behave abnormally when passing boundary (for example, std::string is different in size in two modules)
  • Virtual function call jumps to the wrong position

For example: GCC uses C 11 ABI by default since 4.7, but in order to maintain compatibility, a macro _GLIBCXX_USE_CXX11_ABI is provided to switch back to the old version. If you compile one module with the new ABI and the other module with the old one, then the internal structure of types like std::string will be inconsistent, and the result will be various unpredictable bugs.

In what circumstances do you need to pay special attention to ABI?

For most application developers, ABI is something that is "invisible but must exist". But in the following typical scenarios, you have to pay attention to it:

  • Develop cross-platform libraries : The compiler ABI on Windows and Linux is completely different. To ensure the stability of the library's interface, you need to design the abstraction layer.
  • Maintain a long-running system : If the system components are composed of modules built at different points in time, ABI changes may lead to subsequent upgrade failures.
  • Use third-party dynamic libraries : especially closed source libraries, you must confirm that their build environment matches your project.
  • Embedded development : Cross-compilation is prone to inconsistent ABI due to different toolchain versions.

Common practices when encountering these problems include:

  • Clearly specify compiler and version requirements
  • Use stable intermediate interfaces (such as C-style API)
  • Avoid exposing STL types as public interfaces
  • Control the ABI switch (as mentioned above _GLIBCXX_USE_CXX11_ABI )

How to view or control C ABI?

Different compilers have different ways to view and set up ABIs. Taking GCC as an example, you can determine which ABI is currently using through macro definitions:

 #if defined(_GLIBCXX_USE_CXX11_ABI)
// Use the new version of ABI
#else
// Use old version of ABI
#endif

The way to control the ABI is also usually defined by compilation options or macros. For example, using -D_GLIBCXX_USE_CXX11_ABI=0 in newer GCC can force switch back to the old version of ABI.

In addition, you can also use nm or objdump tools to view the symbol table and observe the name adaptation format to determine whether the ABI is consistent.


Basically that's it. Although ABI is not something you touch every day, it can easily become a hidden pit in specific scenarios. Understand and pay attention in advance, which can save a lot of time for post-scheduling.

The above is the detailed content of Understanding the C ABI. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1545
276
Succinct (PROVE Coin) Price Forecast: 2025, 2026, 2027-2030 Succinct (PROVE Coin) Price Forecast: 2025, 2026, 2027-2030 Aug 11, 2025 am 10:12 AM

Directory What is Succinct (PROVE) Which venture capital supports Succinct (PROVE)? How Succinct (PROVE) Working Principle SP1zkVM and Prover Network OPSuccinct Technology Cross-chain Verification PROVE Token Economics Token Details 2025, 2026, 2027-2030 Succinct (PROVE) Price Forecast Succinct (PROVE) Price Forecast Succinct (PROVE) Price Forecast: Trading Volume Expansion and Listing Momentum 2025-20

What should I do if the application cannot start normally (0xc0000906)? See the solution here What should I do if the application cannot start normally (0xc0000906)? See the solution here Aug 13, 2025 pm 06:42 PM

When opening the software or game, a prompt suddenly appears that "the application cannot start normally (0xc0000906)" appears, and many users will be confused and don't know where to start. In fact, most of these errors are caused by corruption of system files or missing runtime libraries. Don't rush to reinstall the system. This article provides you with several simple and effective solutions to help you quickly restore the program to run. 1. What is the error of 0xc0000906? Error code 0xc0000906 is a common startup exception in Windows systems, which usually means that the program cannot load the necessary system components or running environment when running. This problem often occurs when running large software or games. The main reasons may include: the necessary runtime library is not installed or damaged. The software installation package is endless

C   memory order relaxed example C memory order relaxed example Aug 08, 2025 am 01:00 AM

memory_order_relaxed is suitable for scenarios where only atomicity is required without synchronization or order guarantee, such as counters, statistics, etc. 1. When using memory_order_relaxed, operations can be rearranged by the compiler or CPU as long as the single-threaded data dependency is not destroyed. 2. In the example, multiple threads increment the atomic counter, because they only care about the final value and the operation is consistent, the relaxed memory order is safe and efficient. 3. Fetch_add and load do not provide synchronization or sequential constraints when using relaxed. 4. In the error example, the producer-consumer synchronization is implemented using relaxed, which may cause the consumer to read unupdated data values because there is no order guarantee. 5. The correct way is

How to get the size of a file in C How to get the size of a file in C Aug 11, 2025 pm 12:34 PM

Use the seekg and tellg methods of std::ifstream to obtain file size across platforms. By opening a binary file and positioning it to the end, use tellg() to return the number of bytes; 2. It is recommended to use std::filesystem::file_size for C 17 and above. The code is concise and errors are handled through exceptions. The C 17 standard must be enabled; 3. On POSIX systems, the stat() function can be used to efficiently obtain file size, which is suitable for performance-sensitive scenarios. The appropriate method should be selected based on the compiler and platform, and std::filesystem should be used first (if available), otherwise use ifstream to ensure compatibility, or use st on Unix systems

How to use regular expressions in C How to use regular expressions in C Aug 12, 2025 am 10:46 AM

To use regular expressions in C, you need to include header files and use the functions it provides for pattern matching and text processing. 1. Use std::regex_match to match the full string, and return true only when the entire string conforms to the pattern; 2. Use std::regex_search to find matches at any position in the string; 3. Use std::smatch to extract the capture group, obtain the complete match through matches[0], matches[1] and subsequent sub-matches; 4. Use std::regex_replace to replace the matching text, and support the capture group with references such as $1 and $2; 5. You can add an iset when constructing the regex (

How to fix missing MSVCP71.dll in your computer? There are only three methods required How to fix missing MSVCP71.dll in your computer? There are only three methods required Aug 14, 2025 pm 08:03 PM

The computer prompts "MsVCP71.dll is missing from the computer", which is usually because the system lacks critical running components, which causes the software to not load normally. This article will deeply analyze the functions of the file and the root cause of the error, and provide three efficient solutions to help you quickly restore the program to run. 1. What is MSVCP71.dll? MSVCP71.dll belongs to the core runtime library file of Microsoft VisualC 2003 and belongs to the dynamic link library (DLL) type. It is mainly used to support programs written in C to call standard functions, STL templates and basic data processing modules. Many applications and classic games developed in the early 2000s rely on this file to run. Once the file is missing or corrupted,

C   operator overloading example C operator overloading example Aug 15, 2025 am 10:18 AM

Operator overloading in C allows new behaviors of standard operators to be assigned to custom types, 1. Return new objects through member function overloading; 2. Overload = Modify the current object and return reference; 3. Friend function overloading

How to write a basic Makefile for a C   project? How to write a basic Makefile for a C project? Aug 15, 2025 am 11:17 AM

AbasicMakefileautomatesC compilationbydefiningruleswithtargets,dependencies,andcommands.2.KeycomponentsincludevariableslikeCXX,CXXFLAGS,TARGET,SRCS,andOBJStosimplifyconfiguration.3.Apatternrule(%.o:%.cpp)compilessourcefilesintoobjectfilesusing$

See all articles