Skip to content

Commit 5fe2823

Browse files
authored
Fix Windows ZTS shared-build LNK2001 on _tsrm_ls_cache (#1674)
Drop /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 from the sqlsrv and pdo_sqlsrv EXTENSION() calls in config.w32. On thread-safe (ZTS) shared builds this define made init.cpp / pdo_init.cpp define _tsrm_ls_cache with C linkage (php_sqlsrv.h / php_pdo_sqlsrv.h are included inside an extern "C" block), while the shared core_*.cpp translation units reference it with C++ linkage (core_sqlsrv.h includes php.h outside extern "C"). The linkage mismatch produced: core_stmt.obj : error LNK2001: unresolved external symbol "void * _tsrm_ls_cache" (?_tsrm_ls_cache@@3PEAXEA) fatal error LNK1120: 1 unresolved externals Removing the define makes the Windows shared build resolve the TSRM cache through the engine (tsrm_get_ls_cache()), matching the Linux/macOS config.m4 builds and the Windows static build. NTS builds are unaffected.
1 parent c0edf0c commit 5fe2823

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

source/pdo_sqlsrv/config.w32

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ if( PHP_PDO_SQLSRV != "no" ) {
4949
}
5050
}
5151
ADD_EXTENSION_DEP('pdo_sqlsrv', 'pdo');
52-
EXTENSION("pdo_sqlsrv", pdo_sqlsrv_src_class, PHP_PDO_SQLSRV_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
52+
// Do NOT pass /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 here. On ZTS (thread-safe) shared
53+
// builds it makes pdo_init.cpp define _tsrm_ls_cache with C linkage while the shared
54+
// core_*.cpp reference it with C++ linkage, causing LNK2001. Omitting it matches the
55+
// Linux/macOS (config.m4) builds, which resolve the cache through the engine.
56+
EXTENSION("pdo_sqlsrv", pdo_sqlsrv_src_class, PHP_PDO_SQLSRV_SHARED);
5357
} else {
5458
WARNING("pdo-sqlsrv not enabled; libraries and headers not found");
5559
}

source/sqlsrv/config.w32

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ if( PHP_SQLSRV != "no" ) {
5050
}
5151
}
5252
if (PHP_DEBUG != "yes") ADD_FLAG( "CFLAGS_SQLSRV", "/guard:cf /O2" );
53-
EXTENSION("sqlsrv", sqlsrv_src_class , PHP_SQLSRV_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
53+
// Do NOT pass /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 here. On ZTS (thread-safe) shared
54+
// builds it makes init.cpp define _tsrm_ls_cache with C linkage while the shared
55+
// core_*.cpp reference it with C++ linkage, causing LNK2001. Omitting it matches the
56+
// Linux/macOS (config.m4) builds, which resolve the cache through the engine.
57+
EXTENSION("sqlsrv", sqlsrv_src_class , PHP_SQLSRV_SHARED);
5458
} else {
5559
WARNING("sqlsrv not enabled; libraries and headers not found");
5660
}

0 commit comments

Comments
 (0)