• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

Use VS 2005 compiled library in VS 2008


I've a library that is compiled with VS 2005. I need to use that in a C++ win32 console project in VS 2008. I get an error
fatal error LNK1257: code generation failed

Is it really required to rebuild that library in VS 2008. Just curious, how windows libraries are linked in the projects irrespective of the visual studio versions.


1 Solution
evilrixSenior Software Engineer (Avast)Commented:
>> Is it really required to rebuild that library in VS 2008.
Generally you cannot rely on a library build in one version of a compiler working in another, especially if it's a C++ library. There is no standard ABI defined in the C++ standards doc do each compiler is free to use whatever name-mangling or binary interface is wishes. Vendors often change things between versions to facilitate improvements to the binary code.

What evilrix said is true for C++ compiled libraries without "extern C" linkage, and typically commercial libraries are with C extern linkage. If you are the originator of that library, and want to make the binary form available for future uses without recompile, you need to define C linkage entry points for it. Its not the internal C++ code that is incompatible, its the mangling and other ABI.

So, as I said, best practice is to export using C linkage using __stdcall

Then any Windows compiler and/or version can link your library. But this does limit your use of the C++ classes to that which you can expose via a C interface.

There are downsides to this, like lack of exceptions, lack of direct use of the C++ class inside the library, etc.

Here is a good article for you:


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now