2

I've got a 3d party static library built with some older version of MSVC, and I successfully link it to my application in MSVC10 (VisualStudio2010). Now I upgraded to MSVC11, and I'm unable to link it:

2>LINK : fatal error C1047: The object or library file 'MyLib.lib' was created with an older compiler than other objects; rebuild old objects and libraries

I guess this happens because the lib was compiled with /GL option, so the object files don't really contain COFF, but some intermediate format. I don't have the library source-code to re-compile, and I don't want to make a dll out of it to link dynamically.

Is there a way - maybe some undocumented trick - to "re-compile" these obj's to COFF and eventually link them to MSVC11 application?

Igor R.
  • 14,716
  • 2
  • 49
  • 83

1 Answers1

1

Even if this was possible, you don't want to do this: linking object files that are built against different versions of the CRT usually ends in tears. More specifically, if two such object files both use the C++ Standard Library, it is all but certain that you will violate the One Definition Rule (ODR).

If you cannot rebuild the module using Visual C++ 2012, then you should encapsulate it within a dynamic library, built with Visual C++ 2010, and avoid using any C++ Standard Library types in the interface of that DLL.

James McNellis
  • 348,265
  • 75
  • 913
  • 977
  • In this specific case it wouldn't cause any ODR violation. But I'm not sure I understand your point: how presence or absence of LTCG affects the ODR issue? If this lib were built *without* LTCG, I could link it without any problem, just like I link libs built even by GCC. – Igor R. Dec 11 '12 at 19:05
  • 1
    I'm saying that even if you could somehow work around the LTCG issue (though I am not aware of any way to do this), you'd then run headlong into the ODR issue. If you try to link objects built with VC10 and VC11 and both use the C++ Standard Library, you should get a lovely linking error of the form `dev11object.lib(dev10object.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in dev11object.obj`. If you are not using the C++ Standard Library in both object files, then you might have more options, if you can work around the LTCG issue. – James McNellis Dec 11 '12 at 19:18