Difference between API and ABI

前端 未结 9 2000
余生分开走
余生分开走 2020-12-04 04:34

I am new to linux system programming and I came across API and ABI while reading Linux System Programming.

Definition of API :

相关标签:
9条回答
  • 2020-12-04 04:57

    I mostly come across these terms in the sense of an API-incompatible change, or an ABI-incompatible change.

    An API change is essentially where code that would have compiled with the previous version won't work anymore. This can happen because you added an argument to a function, or changed the name of something accessible outside of your local code. Any time you change a header, and it forces you to change something in a .c/.cpp file, you've made an API-change.

    An ABI change is where code that has already been compiled against version 1 will no longer work with version 2 of a codebase (usually a library). This is generally trickier to keep track of than API-incompatible change since something as simple as adding a virtual method to a class can be ABI incompatible.

    I've found two extremely useful resources for figuring out what ABI compatibility is and how to preserve it:

    • The list of Do's and Dont's with C++ for the KDE project
    • Ulrich Drepper's How to Write Shared Libraries.pdf (primary author of glibc)
    0 讨论(0)
  • 2020-12-04 05:02

    API: Application Program Interface

    This is the set of public types/variables/functions that you expose from your application/library.

    In C/C++ this is what you expose in the header files that you ship with the application.

    ABI: Application Binary Interface

    This is how the compiler builds an application.
    It defines things (but is not limited to):

    • How parameters are passed to functions (registers/stack).
    • Who cleans parameters from the stack (caller/callee).
    • Where the return value is placed for return.
    • How exceptions propagate.
    0 讨论(0)
  • 2020-12-04 05:08

    (Application Binary Interface) A specification for a specific hardware platform combined with the operating system. It is one step beyond the API (Application Program Interface), which defines the calls from the application to the operating system. The ABI defines the API plus the machine language for a particular CPU family. An API does not ensure runtime compatibility, but an ABI does, because it defines the machine language, or runtime, format.

    Courtesy

    0 讨论(0)
  • 2020-12-04 05:10

    This is my layman explanations:

    • API - think of include files. They provide programming interfaces.
    • ABI - think of kernel module. When you run it on some kernel, it has to agree on how to communicate without include files, i.e. as low-level binary interface.
    0 讨论(0)
  • 2020-12-04 05:10

    API - Application Programming Interface is a compile time interface which can is used by developer to use non-project functionality like library, OS, core calls in source code

    ABI[About] - Application Binary Interface is a runtime interface which is used by a program during executing for communication between components in machine code

    0 讨论(0)
  • 2020-12-04 05:11

    The API is what humans use. We write source code. When we write a program and want to use some library function we write code like:

     long howManyDecibels = 123L;
     int ok = livenMyHills( howManyDecibels);
    

    and we needed to know that there is a method livenMyHills(), which takes a long integer parameter. So as a Programming Interface it's all expressed in source code. The compiler turns this into executable instructions which conform to the implementation of this language on this particular operating system. And in this case result in some low level operations on an Audio unit. So particular bits and bytes are squirted at some hardware. So at runtime there's lots of Binary level action going on which we don't usually see.

    0 讨论(0)
提交回复
热议问题