Are C ++ libraries created with different versions of Visual Studio compatible with each other?

I am creating an open-source C ++ library using Visual Studio 2005. I would like to provide ready-made libraries along with the source code. Will these libraries created with VS2005 also work with newer versions of Visual Studio (e.g. VS Express Edition 2008)? Or do I need to provide separate libraries for the VS version?

+18
c ++
Oct 21 '09 at 12:05
source share
4 answers

If you distribute static libraries, you can distribute version-dependent libraries depending on what you do. If you only make calls in the OS, then you may be fine. Perhaps the functions of RTL. But if you use any functions, classes or templates of the standard C ++ library, then probably not.

When distributing a DLL, you will need separate libraries for each version of VS. Sometimes you even need separate libraries for different levels of service packages. And, as VolkerK already mentioned, your library users will have to use compatible compiler and linker settings. And even if you do everything right, users may need a link to other libraries that are somehow incompatible with yours.

Because of these problems, instead of wasting time creating all these libraries for your users, I would spend time making them as simplified as possible so that users can create them on their own with minimal fuss.

+14
Oct. 21 '09 at 12:09
source share

Not normal, no. Libraries created using VS tools are linked to the "Microsoft C Runtime" (called MSVCRT followed by version number), which provides standard C and C ++ library functions, and if you try to run a program that requires two different versions of this runtime , errors will occur.

In addition to this, different versions of the compiler produce different compiled code, and code from one version of the compiler is often incompatible with another, except in the most trivial cases (and if they pop out the same code, then it makes no sense to have different versions :))

+17
Oct 21 '09 at 12:13
source share

In the general case, it is impossible to link libraries built with different compilers, different versions of the same compiler and even different settings of the same compiler version and get a working application. (Although this may work for certain subsets of the std language and library.) There is no standard binary interface for C ++ - not even one for some common platform, as it is in C.

To do this, you either need to wrap your library in API C, or you will have to send a binary file for each compiler, compiler version and compiler settings that you want to support.

+6
Oct 21 '09 at 12:21
source share

If your library project is a static library, then you will have to provide an assembly for each version of Visual Studio that you want your users to be in. In your example, this is equivalent to providing VS2005 and the VS2008 library.

If your library project is a dynamic library, then you are somewhat shy away from problems, but that means users need to make sure that they are using the "Microsoft C Runtime" compatible with your build environment. You can exclude these criteria if you statically link "Microsoft C Runtime" in your dynamic library.

+2
Jan 6 '17 at 4:00
source share



All Articles