Use VS 2005 compiled library in VS 2008

Posted on 2009-04-22
Last Modified: 2012-05-06

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.


Question by:haider
    LVL 39

    Expert Comment

    >> 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.
    LVL 40

    Accepted Solution

    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

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now