C++ Library Compatibility
I am currently writing a library and am considering moving from GCC 4.1.2 to 4.5.2 (latest release) of GCC. If I compile my code into a static library can I assume compiler compatibility (on the same OS obviously) should be a non-issue for clients?
EDIT To further clarify: if I provide a client a statically linked library compiled with gcc 4.5.2, what restrictions does this pl开发者_运维问答ace on users of this library in terms of the compiler and version they must use?
Just came across this which I believe answers my question from http://gcc.gnu.org/bugs/#nonbugs:
ABI changes The C++ application binary interface (ABI) consists of two components: the first defines how the elements of classes are laid out, how functions are called, how function names are mangled, etc; the second part deals with the internals of the objects in libstdc++. Although we strive for a non-changing ABI, so far we have had to modify it with each major release. If you change your compiler to a different major release you must recompile all libraries that contain C++ code. If you fail to do so you risk getting linker errors or malfunctioning programs. Some of our Java support libraries also contain C++ code, so you might want to recompile all libraries to be safe. It should not be necessary to recompile if you have changed to a bug-fix release of the same version of the compiler; bug-fix releases are careful to avoid ABI changes. See also the compatibility section of the GCC manual.
Remark: A major release is designated by a change to the first or second component of the two- or three-part version number. A minor (bug-fix) release is designated by a change to the third component only. Thus GCC 3.2 and 3.3 are major releases, while 3.3.1 and 3.3.2 are bug-fix releases for GCC 3.3. With the 3.4 series we are introducing a new naming scheme; the first release of this series is 3.4.0 instead of just 3.4.
From this as I understand it I'll need to ensure clients are linking my library in with a major-release compatable version of gcc.
It doesn't really matter if you are providing a static library or dynamic library, the users will still need to use a compatable compiler/linker to link against it. Usually when GCC does a ABI change they offer a switch that can be set to use the old ABI. I know that they did that when they went from 3.x to 4.x and even a couple of the releases within the 4.x series.
精彩评论