c++dynamic-linkingdynamic-library

What does C++ standard say about dynamic libraries?


What does C++ standard say about dynamic libraries? I heard that it completely ignores them (for some reason) - if it's true, why so?


Solution

  • There are, effectively, just 2 major pitfalls with dynamic libraries, where you can trivially break the assumptions made in the C++ Standard such that it doesn't match the abstract machine:

    In both cases, it's still your responsibility as a developer to ensure that you stay within the bounds of the abstract machine, and not cause any observable behavior which would contradict it.

    So much for the theory.

    The reality is that, in both cases, most dynamic libraries actually don't even try to act as if the system/process as a whole was compliant with the C++ abstract machine.

    Instead, C++ is only expected to be fully functional within each dynamic library, while the entire external interface is entirely aware of dynamic linkage, symbol visibility etc., and avoids any C++ features which could potentially expose undefined behavior on the boundaries. Each library – on its own – acts in compliance with the abstract machine.