Libraries and compiler compatibility on Windows
I have an application built on VS2005 which uses a static library built using VS6.0.
I have noticed an issue of incorrect function getting called from a static library linked at compiled time. Note that this static library was built using Visual Studio 6.0. Whereas my application which is using the static library for linking at compile time is built using VS2005.
At run time, I see that incorrect/different functions are getting called rather than the ones which are supposed to get called.
To solve this issue:
I rebuilt the static library (.lib) using VS2005. Then this newly built static library was used for compilation along with my application on VS2005. Then the functions are getting called correctly.
I have 2 questions here:
1) This means that if there is any static library built with older version of VS6.0, then it will not work correctly with an application built with VS2005. We need to rebuild it with the same compiler as the application is built with. Is this true? why this happens in case of static libraries?
2) If above point-1 is true, then isn't it necessary to rebuild DDLs also with VS2005? If no, then why it is ok that a DLL built with older version of compiler works fine with application built with newer compiler version?
The answer to your first question is positive. You need to compile and *link* every static library the same compiler and linker's major version. There have been several significant ABI changes since Visual C++ 5.6 so the binaries that that compiler produced will not be compatible with those that VS2005 produces. Needless to say, the linkage will also fail in such cases.
With respect to DLLs, the secret lies in the fact that the linkage takes place at runtime. It's as if you are linking the same library (DLL) into your main() every time the DLL is loaded. However, since the DLLs themselves contain outdated ABIs, you need to recompile them to avoid unexpected behavior. C++ has changed a lot since the time of Visual C++ 5.6 and some of these changes dictated ABI changes as well (new datatypes have been added, namespaces etc.).
Last Post: 09-12-2007, 07:50 AM
By toratoratora in forum C++
Last Post: 03-07-2007, 08:24 AM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL