cppfw / svgren

:camera: SVG rendering library in C++
MIT License
206 stars 41 forks source link

VS2019 link error with zlib_static.1.2.11.4 #72

Closed saeitsystems closed 4 years ago

saeitsystems commented 4 years ago

We want to change our svgren projekt to VS2019. Everything compiles links and runs fine in the debug version. On linking the release Version I get the following error:

linking ... LINK : fatal error C1047: The object or library file 'E:\sae\nfs\VC2019\packages\zlib_static.1.2.11.4\build\native\..\..\\build\native\lib\Win32\v142\Release\MultiThreadedDLL\zlib.lib' was created with an older compiler than other objects; rebuild old objects and libraries LINK : fatal error LNK1257: code generation failed Done building project "Setit.vcxproj" -- FAILED. I think it's a problem with the static zlib library.

igagis commented 4 years ago

Could you check that in release configuration you have non-debug runtime library selected in Project Master Settings / C/C++ Settings / Runtime Library? It should be Multithreaded DLL

igagis commented 4 years ago

also check that in release configuration you have same value in C/C++ / Code Generation / Runtime Library

saeitsystems commented 4 years ago

Hi, thanks for your quick answer. My settings seem to be correct: VS2019-settings1 VS2019-settings2

igagis commented 4 years ago

ok, let me see if I can reproduce it on my end

igagis commented 4 years ago

I have reproduced it at some extent, also getting link error wit release build, but about different object file. No idea what's wrong so far. The other strange thing is that it work on CI machine. Will investigate further.

igagis commented 4 years ago

After updating my VS2019 to version 16.4.3 error is no longer reproducible. Could you check also that you have your VS2019 up to date?

saeitsystems commented 4 years ago

I'm sorry but my Version already was up to date:

Microsoft Visual Studio Professional 2019
Version 16.4.3
VisualStudio.16.Release/16.4.3+29709.97
Microsoft .NET Framework
Version 4.7.03056

Installed Version: Professional

Visual C++ 2019   00435-60000-00000-AA849
Microsoft Visual C++ 2019

are you using the mfc version v142

saeitsystems commented 4 years ago

I exchanged the release library with the debug version and everything links and runs as expected. So it must be a problem with the release version of the zlib.lib file

igagis commented 4 years ago

ok, I will check that

igagis commented 4 years ago

I see you are building your project for x86 (Win32), what if you try to build it for x64, do you get the same linking error?

I had a look at how zlib_static package is built and I don't see anything wrong there so far. And also it works for my projects for all configurations.

It is also possible that in your project you have some option set to some value which conflicts with that of the zlib_static, but then it is strange why other packages work...

saeitsystems commented 4 years ago

I don't think our project will compile and link on x64 without a lot of work ..... For now i can work with the debug version of the zlib_static in the release. Could you rebuild the zlib_static release version for win32 with the actual VS2019 version and attach it to this thread or send it per mail?

igagis commented 4 years ago

I have rebuilt the zlib_static package with VS2019 16.4.3, now the package version is 1.2.11.5. Could you try to update it and see if it helps?

saeitsystems commented 4 years ago

This solved the problem! Thanks.

But in VS2019 I found another problem with three of your packages

Package info is:

 <package id="cairo_static" version="1.15.4.5" targetFramework="native" />
  <package id="libmikroxml" version="0.1.19" targetFramework="native" />
  <package id="libpapki" version="1.0.74" targetFramework="native" />
  <package id="libpng" version="1.6.28.1" targetFramework="native" />
  <package id="libpng.redist" version="1.6.28.1" targetFramework="native" />
  <package id="libpng_native" version="1.6.30" targetFramework="native" />
  <package id="libpng_native.redist" version="1.6.30" targetFramework="native" />
  <package id="libpng_static" version="1.4.1.6" targetFramework="native" />
  <package id="libsvgdom" version="0.3.31" targetFramework="native" />
  <package id="libsvgren" version="0.4.64" targetFramework="native" />
  <package id="libunikod" version="2.0.38" targetFramework="native" />
  <package id="libutki" version="1.1.70" targetFramework="native" />
  <package id="Microsoft.CppCoreCheck" version="14.0.24210.1" targetFramework="native" />
  <package id="Microsoft.Gsl" version="0.1.2.1" targetFramework="native" />
  <package id="pixman_static" version="0.32.4.7" targetFramework="native" />
  <package id="zlib" version="1.2.8.8" targetFramework="native" />
  <package id="zlib.v120.windesktop.msvcstl.dyn.rt-dyn" version="1.2.8.8" targetFramework="native" />
  <package id="zlib.v140.windesktop.msvcstl.dyn.rt-dyn" version="1.2.8.8" targetFramework="native" />
  <package id="zlib_native" version="1.2.11" targetFramework="native" />
  <package id="zlib_native.redist" version="1.2.11" targetFramework="native" />
  <package id="zlib_static" version="1.2.11.5" targetFramework="native" />

But VS2019 also polls / restores older versions of the package

libpapki.1.0.71
libutki.1.1.58
zlib_static.1.2.11.4

My package folder: NuGetPackages_VS2019

igagis commented 4 years ago

I was using zlib, libpng etc. libs packaged by someone else before, but when I added v142 support I had to repackage those myself, since those other packages did not support v142. So, now my libs are not dependent on any third party packages. Those old third party packages remain installed in your project, and you can remove them now.

The following packages are not needed, you can remove those:

 <package id="libpng" version="1.6.28.1" targetFramework="native" />
 <package id="libpng.redist" version="1.6.28.1" targetFramework="native" />
 <package id="libpng_native" version="1.6.30" targetFramework="native" />
 <package id="libpng_native.redist" version="1.6.30" targetFramework="native" />
 <package id="zlib" version="1.2.8.8" targetFramework="native" />
 <package id="zlib.v120.windesktop.msvcstl.dyn.rt-dyn" version="1.2.8.8" targetFramework="native" />
 <package id="zlib.v140.windesktop.msvcstl.dyn.rt-dyn" version="1.2.8.8" targetFramework="native" />
 <package id="zlib_native" version="1.2.11" targetFramework="native" />
 <package id="zlib_native.redist" version="1.2.11" targetFramework="native" />

As I understand, the following packages you installed for something else than svgren:

<package id="Microsoft.CppCoreCheck" version="14.0.24210.1" targetFramework="native" />
 <package id="Microsoft.Gsl" version="0.1.2.1" targetFramework="native" />

If not, then you can remove those as well, I don't know what those are.

As for why old versions of

libpapki.1.0.71
libutki.1.1.58
zlib_static.1.2.11.4

are still present, I don't know, perhaps those are not pulled, but just remained undeleted. Sometimes VS nuget have some glitches... Perhaps, if you do a fresh checkout of your project and sync the packages those old versions will not be pulled.

igagis commented 4 years ago

Note also, that info about installed nuget packages also present in .vcxproj files, sometimes I had to remove old packages manually from those files (those are XML files inside).

igagis commented 4 years ago

Good that the link problem was resolved. Let me know if you have link problems with other packages in future, I might need to rebuild them also...

saeitsystems commented 4 years ago

Thanks for the hint. I think we had some merge problems with swapping to VS2019. Removing the obsolete libraries worked well too!