1

My Visual Studio 2017 C++ project takes as inputs:

  • Source code
  • Library compiled by VS2015
  • Library compiled by 3rd party using VS2017

The linker gives errors:

1>  functionallib.lib(bcp_toplevel.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
1>LINK : fatal error C1900: Il mismatch between 'P1' version '20161212' and 'P2' version '20150812'
1>LINK : fatal error LNK1257: code generation failed

My understanding is that VS2015 and VS2017 libraries are binary compatible so I am surprised by this error.

How can I diagnose exactly what is wrong and how can I fix it?

DavidA
  • 2,053
  • 6
  • 30
  • 54
  • Maybe [this](https://social.msdn.microsoft.com/Forums/vstudio/en-US/9abfefe0-56bd-4a82-ae14-b08f262972bd/fatal-error-c1900-il-mismatch-between-p1-version-20080116-and-p2-version-20070207?forum=vclanguage) helps. – Jabberwocky Jan 24 '18 at 09:48
  • No dlls compiled with different compilers will not be binary compatible, you'd have to write a wrapper dll, in particular if the library uses any stl containers they are also not compatible between compiler versions. – EdChum Jan 24 '18 at 09:48
  • 2
    Or [this SO article](https://stackoverflow.com/questions/8959973/il-mismatch-between-p1-version-20080116-and-p2-version-20070207) may help too. – Jabberwocky Jan 24 '18 at 09:50
  • Are any of your libraries you consume built with LTCG? If thats the case then you need matching tools to consume them – Mike Vine Jan 24 '18 at 09:50
  • @MichaelWalz that post looks like a dupe for this question IMO – EdChum Jan 24 '18 at 09:50
  • 1
    @EdChum thats not the case between 2015 and 2017 - they were explicitely designed to not break - see [this](https://stackoverflow.com/questions/44288837/binary-compatibility-between-vs2017-and-vs2015) post. – Mike Vine Jan 24 '18 at 09:52
  • @EdChum yes maybe, but I'm not sure that's why I didn't cv it. – Jabberwocky Jan 24 '18 at 09:53
  • @MikeVine but the library compiled with VS2015 could have been compiled with an older toolset such as v120. – Jabberwocky Jan 24 '18 at 09:54
  • @MichaelWalz thats fair, I assumed using the default tool sets for 2015/2017. When someone says "built with 2015" they normally mean "built with v140 toolset", and the same for vs2017 -> v141 toolset. – Mike Vine Jan 24 '18 at 09:56
  • You should compile that "Library compiled by VS2015" you mention with VS2017. – Jabberwocky Jan 24 '18 at 10:00
  • @MikeVine I didn't know that 141 and 140 were binary compatible, stuck on VS 2015 so have not looked at VS2017 at all, still it does depend on which toolset was targeted – EdChum Jan 24 '18 at 10:19
  • Thanks for your replies. I did indeed mean "built with 2015" -> "built with v140 toolset", and the same for vs2017 -> v141 toolset. I guess the logical next step is to compile everything in vs2017, but I thought that shouldn't be necessary. I'll have to check the LTCG setting with the 3rd party. – DavidA Jan 24 '18 at 10:21
  • 1
    @DavidA it shouldn't be neceessay unless LTCG has been used. Thats what the first (warning) line in your output says - that functionallib *has* been built with LTCG and that the linker is restarting itself because of it. That warning is usually just that - a warning - but the fact you get the next line of error heavily implies that LTCG is indeeed causing your issues. – Mike Vine Jan 24 '18 at 10:23
  • @MikeVine Thanks. I'll ask the 3rd party to rebuild functionallib without LTCG. – DavidA Jan 24 '18 at 10:33
  • If removing LTCG does fix this, could you post an answer and accept it in due course as this makes this question distinctly different from the other post, thanks – EdChum Jan 24 '18 at 10:45
  • @EdChum Yes, I'll update this when I know the outcome. – DavidA Jan 24 '18 at 10:50
  • @DavidA Did you find out if it was LTCG that caused the error? I came here from Google and would like to know what the solution was. – Ostinger May 30 '22 at 07:40
  • 1
    @Ostinger I'm sorry, I don't remember now. – DavidA May 30 '22 at 11:04

0 Answers0