microsoft / php-sdk-binary-tools

Tool kit for building PHP under Windows
BSD 2-Clause "Simplified" License
271 stars 78 forks source link

Unable to build PHP master with VS 2019 because of iconv/sqlite3 dependency mismatch #72

Closed dwgebler closed 3 years ago

dwgebler commented 3 years ago

VS 2019 installed and updated to latest, attempting to build PHP-8.1.0-dev (master) with sqlite3 support (configure --with-sqlite3 ...) results in following error, which can only be resolved by disabling libiconv and libxml, or by not including sqlite3.

libiconv_a.lib(iconv1.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
fatal error C1047: The object or library file 'D:\php8-sync\phpmaster\vs16\x64\deps\lib\libsqlite3_a.lib' was created by a different version of the compiler than other objects like 'D:\php8-sync\phpmaster\vs16\x64\deps\lib\libiconv_a.lib'; rebuild all objects and libraries with the same compiler
LINK : fatal error LNK1257: code generation failed
NMAKE : fatal error U1077: '"D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\HostX64\x64\link.exe"' : return code '0x4e9'
cmb69 commented 3 years ago

Are you using the latest dependencies (check with phpsdk_deps -c)?

dwgebler commented 3 years ago

@cmb69

Configuration: master-vs16-x64-staging

No updates are available.
dwgebler commented 3 years ago

This is fixable by exporting environment variable set LDFLAGS="/d2:-AllowCompatibleILVersions" before running configure, it does not appear to be an issue with this repo, rather the version of the iconv lib supplied by https://windows.php.net/downloads/php-sdk/deps/vs16/x64/

cmb69 commented 3 years ago

I usually build ext/sqlite as shared extension, so I didn't notice this issue so far. But indeed, when building ext/sqlite as static extension, I'm hitting C1047 as well (VS 16.8.4, libiconv-1.16-3, sqlite3-3.33.0). That error has already been very annoying several times in the past, since it required to rebuilt several packages to be able to do the snapshot builds, and those rebuilt packages didn't work with older VS versions, what caused problems for others. So constantly rebuilding libiconv doesn't appear to be a good solution.

/d2:-AllowCompatibleILVersions

Thank you! I wasn't aware of this undocumented linker option. It might make sense to add it by default for the Windows builds to mitigate this issue. For now, I have at least documented it.

cmb69 commented 3 years ago

/cc @Jan-E, @weltling, may be interested in this info as well. According to https://developercommunity.visualstudio.com/content/problem/316532/c1047-after-update-from-157-to-158.html, it is safe to use it.

Jan-E commented 3 years ago

Thanks. I never ran into C1047 AFAIK, but I have added set LDFLAGS="/d2:-AllowCompatibleILVersions" to my VS16 build environment.

Edit O, wait. This was the error we ran into when PHP 7.4 was compiled with VS16 in the beginning.