I am trying to compile the SAP SqlAnywhere php extension for use with PHP 8.0.12; the source for this extension I downloaded from this location. This site has compiled versions of the extension for various versions of PHP up until PHP 7.4. As we are currently using PHP 8.0.12 on our development server, I wanted to build this extension for this version, or for PHP 8.0.13.
I managed to setup the development environment correctly on Windows 10, having installed Visual Studio 2019
including Visual C++ 2015-2022 Redistributable
and git
. Using this environment I have been able to build the extension for PHP 7.4 without issues, but when I try build for PHP 8.0.12, I get the following errors reported:
$ nmake
Microsoft (R) Program Maintenance Utility Version 14.29.30137.0
Copyright (C) Microsoft Corporation. All rights reserved.
sacapidll.c
sqlany_dbg.c
sqlanywhere.c
extsqlanywheresqlanywhere.c(773): error C2146: syntax error: missing ')' before identifier 'TSRMLS_DC'
extsqlanywheresqlanywhere.c(773): error C2061: syntax error: identifier 'TSRMLS_DC'
extsqlanywheresqlanywhere.c(773): error C2059: syntax error: ';'
extsqlanywheresqlanywhere.c(773): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(775): error C2449: found '{' at file scope (missing function header?)
extsqlanywheresqlanywhere.c(780): error C2059: syntax error: '}'
extsqlanywheresqlanywhere.c(1002): error C2146: syntax error: missing ')' before identifier 'TSRMLS_DC'
extsqlanywheresqlanywhere.c(1002): error C2061: syntax error: identifier 'TSRMLS_DC'
extsqlanywheresqlanywhere.c(1002): error C2059: syntax error: ';'
extsqlanywheresqlanywhere.c(1002): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(1004): error C2449: found '{' at file scope (missing function header?)
extsqlanywheresqlanywhere.c(1007): error C2059: syntax error: '}'
extsqlanywheresqlanywhere.c(1194): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(1194): error C2198: 'php_error_docref': too few arguments for call
extsqlanywheresqlanywhere.c(1246): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(1246): error C2198: 'php_error_docref': too few arguments for call
extsqlanywheresqlanywhere.c(1258): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(1258): error C2198: 'php_error_docref': too few arguments for call
extsqlanywheresqlanywhere.c(1306): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(1306): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(1347): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(1347): error C2198: 'php_error_docref': too few arguments for call
extsqlanywheresqlanywhere.c(1415): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(1415): error C2198: 'php_error_docref': too few arguments for call
extsqlanywheresqlanywhere.c(1462): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(1462): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(1540): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(1540): error C2198: 'php_error_docref': too few arguments for call
extsqlanywheresqlanywhere.c(1678): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(1677): error C2198: 'zend_fetch_resource2_ex': too few arguments for call
extsqlanywheresqlanywhere.c(1678): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(1699): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(1699): error C2198: 'php_error_docref': too few arguments for call
extsqlanywheresqlanywhere.c(1725): error C2146: syntax error: missing ')' before identifier 'TSRMLS_DC'
extsqlanywheresqlanywhere.c(1725): error C2061: syntax error: identifier 'TSRMLS_DC'
extsqlanywheresqlanywhere.c(1725): error C2059: syntax error: ';'
extsqlanywheresqlanywhere.c(1725): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(1727): error C2449: found '{' at file scope (missing function header?)
extsqlanywheresqlanywhere.c(1763): error C2059: syntax error: '}'
extsqlanywheresqlanywhere.c(1855): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(1854): error C2198: 'zend_fetch_resource2_ex': too few arguments for call
extsqlanywheresqlanywhere.c(1855): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(1866): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(1866): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(1870): error C2059: syntax error: 'while'
extsqlanywheresqlanywhere.c(1870): error C2059: syntax error: 'return'
extsqlanywheresqlanywhere.c(1870): error C2059: syntax error: '}'
extsqlanywheresqlanywhere.c(1871): error C2059: syntax error: '}'
extsqlanywheresqlanywhere.c(1878): error C2099: initializer is not a constant
extsqlanywheresqlanywhere.c(1880): error C2143: syntax error: missing '{' before '->'
extsqlanywheresqlanywhere.c(1880): error C2059: syntax error: '->'
extsqlanywheresqlanywhere.c(1884): error C2143: syntax error: missing '{' before '->'
extsqlanywheresqlanywhere.c(1884): error C2059: syntax error: '->'
extsqlanywheresqlanywhere.c(1885): error C2143: syntax error: missing '{' before '->'
extsqlanywheresqlanywhere.c(1885): error C2059: syntax error: '->'
extsqlanywheresqlanywhere.c(1886): error C2143: syntax error: missing '{' before '->'
extsqlanywheresqlanywhere.c(1886): error C2059: syntax error: '->'
extsqlanywheresqlanywhere.c(1887): error C2143: syntax error: missing '{' before '->'
extsqlanywheresqlanywhere.c(1887): error C2059: syntax error: '->'
extsqlanywheresqlanywhere.c(1888): error C2143: syntax error: missing '{' before '->'
extsqlanywheresqlanywhere.c(1888): error C2059: syntax error: '->'
extsqlanywheresqlanywhere.c(1889): error C2143: syntax error: missing '{' before '->'
extsqlanywheresqlanywhere.c(1889): error C2059: syntax error: '->'
extsqlanywheresqlanywhere.c(1891): error C2059: syntax error: 'if'
extsqlanywheresqlanywhere.c(1903): warning C4047: 'function': 'sqlany_result_t *' differs in levels of indirection from 'int'
extsqlanywheresqlanywhere.c(1903): warning C4024: 'cache_result': different types for formal and actual parameter 1
extsqlanywheresqlanywhere.c(1903): error C2099: initializer is not a constant
extsqlanywheresqlanywhere.c(1904): error C2059: syntax error: 'if'
extsqlanywheresqlanywhere.c(1907): error C2059: syntax error: 'else'
extsqlanywheresqlanywhere.c(1910): error C2059: syntax error: 'if'
extsqlanywheresqlanywhere.c(1920): error C2059: syntax error: 'else'
extsqlanywheresqlanywhere.c(1932): error C2059: syntax error: 'if'
extsqlanywheresqlanywhere.c(1933): error C2059: syntax error: 'do'
extsqlanywheresqlanywhere.c(1933): error C2059: syntax error: 'while'
extsqlanywheresqlanywhere.c(1939): error C2059: syntax error: '}'
extsqlanywheresqlanywhere.c(2062): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(2061): error C2198: 'zend_fetch_resource2_ex': too few arguments for call
extsqlanywheresqlanywhere.c(2062): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(2072): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(2072): error C2198: 'php_error_docref': too few arguments for call
extsqlanywheresqlanywhere.c(2077): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(2077): error C2198: 'php_error_docref': too few arguments for call
extsqlanywheresqlanywhere.c(2129): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(2128): error C2198: 'zend_fetch_resource2_ex': too few arguments for call
extsqlanywheresqlanywhere.c(2129): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(2139): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(2139): error C2198: 'php_error_docref': too few arguments for call
extsqlanywheresqlanywhere.c(2192): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(2191): error C2198: 'zend_fetch_resource_ex': too few arguments for call
extsqlanywheresqlanywhere.c(2192): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(2227): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(2226): error C2198: 'zend_fetch_resource_ex': too few arguments for call
extsqlanywheresqlanywhere.c(2227): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(2237): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(2237): error C2198: 'php_error_docref': too few arguments for call
extsqlanywheresqlanywhere.c(2266): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(2265): error C2198: 'zend_fetch_resource_ex': too few arguments for call
extsqlanywheresqlanywhere.c(2266): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(2289): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(2288): error C2198: 'zend_fetch_resource2_ex': too few arguments for call
extsqlanywheresqlanywhere.c(2289): error C2059: syntax error: ')'
extsqlanywheresqlanywhere.c(2318): error C2146: syntax error: missing ')' before identifier 'TSRMLS_CC'
extsqlanywheresqlanywhere.c(2317): error C2198: 'zend_fetch_resource2_ex': too few arguments for call
extsqlanywheresqlanywhere.c(2318): fatal error C1003: error count exceeds 100; stopping compilation
NMAKE : fatal error U1077: '"C:Program Files (x86)Microsoft Visual Studio2019CommunityVCToolsMSVC14.29.30133binHostX86x86cl.exe"' : return code '0x2'
Stop.
Clearly something is missing from the PHP 8.0.12 core that is present in PHP 7.4 – I think it has something to do with TSRMLS_DC
not being defined, as this is the error that is reported first.
Can anyone shed some light on this error/these errors and let me know if there is some way to resolve the missing dependencies so that this extension builds correctly?
2
Answers
I found the answer to this on this site. The
TSRMLS_DC
that the compiler is complaining about isThread-Safe Resource Manager
macros which were previously required, but are no longer need for PHP 8. These can just be removed from the code.After removing those macros, the source will compile, but when the extension runs, a number of warnings, such as the following, will be issued by PHP:
The reason for these warnings is that PHP 8 is stricter on requiring
arginfo
definitions for all the extension functions.You can define these blocks for all of the functions, as outlined in the link above, to get rid of these warnings.
Step by step solution, but for Linux – yes, the question is about Windows, but one can save some time by coping the required by PHP8 pieces of code. Attachments marked with brackets are below the ordered list:
Dockerfile
(b)sasql_php/sqlanywhere.c
, after the line24
…ZEND_BEGIN_ARG_INFO(arginfo_sasql_stmt_bind_param_ex, 0)
…zend_function_entry sqlanywhere_functions[] = {
and ending with};
with the (e)…if( object_init( return_value ) == FAILURE ) { RETURN_FALSE; }
(just look for the phraseobject_init
) with justobject_init( return_value );
docker build -t php-sqlanywhere12-compiler:8.0-cli-alpine .
docker run --rm -v "/path/on/the/host:/module" php-sqlanywhere12-compiler:8.0-cli-alpine /bin/sh -c "cp /sasql_php/modules/sqlanywhere.so /module/php-8.0.0_sqlanywhere.so"
/path/on/the/host
a) https://wiki.scn.sap.com/wiki/display/SQLANY/The+SAP+SQL+Anywhere+PHP+Module – at the very bottom
b)
c)
d)
e)