I made some changes to a shared library on a linux platform and sent the updated library to the end user. The end user has reported that they believe the binary compatibility has been broken (not really sure how they know that).
The changes I made were to internal classes (user doesn't have the header files):
I made 3 different changes:
- added a protected static member variable to a class (didn't really need to be protected)
- added a private static member to a class
- added a static variable to a cpp file (in a non-anonymous namespace)
Which of these changes (if any) can break binary compatibility and how should I add a static variable so that it does not break binary compatibility? Or is adding a static variable generally safe for preserving binary compatibility?
Example of the change I made (denoted by +
)
internal .h file:
class A
{
protected:
+ static Mutex m;
}
internal cpp file
void A::doSomething
{
+ m.Lock();
...
+ m.Unlock();
}
static
member variables inside a class have external linkage, so they are visible in the binary.static
variables outside a class have internal linkage (gotta love C++) so they are invisible outside the library. But neither changes the size or layout of objects, nor any function signatures. From an API perspective, old code should be binary-compatible with a new dynamic library that is changed only in the ways you describe. – John Bollinger