Error while compiling on macOS
Hi!
Following @jmikola's feedback on https://github.com/mongodb/mongo-php-driver/pull/1463 (thanks for it!) I tried to compile the extension manually. I stumble a problem I'm not able to find online:
$ ./configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether cc accepts -g... yes
checking for cc option to enable C11 features... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-apple-darwin22.2.0
checking host system type... x86_64-apple-darwin22.2.0
checking target system type... x86_64-apple-darwin22.2.0
checking for PHP prefix... /usr/local/Cellar/[email protected]/5.6.40_9
checking for PHP includes... -I/usr/local/Cellar/[email protected]/5.6.40_9/include/php -I/usr/local/Cellar/[email protected]/5.6.40_9/include/php/main -I/usr/local/Cellar/[email protected]/5.6.40_9/include/php/TSRM -I/usr/local/Cellar/[email protected]/5.6.40_9/include/php/Zend -I/usr/local/Cellar/[email protected]/5.6.40_9/include/php/ext -I/usr/local/Cellar/[email protected]/5.6.40_9/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/Cellar/[email protected]/5.6.40_9/pecl/20131226
checking for PHP installed headers prefix... /usr/local/Cellar/[email protected]/5.6.40_9/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking whether to enable MongoDB support... yes, shared
./configure: line 5242: syntax error near unexpected token `-Wmissing-format-attribute,'
./configure: line 5242: ` AX_CHECK_COMPILE_FLAG(-Wmissing-format-attribute, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wmissing-format-attribute" ,, -Werror)'
I'm not sure whether this may be due to master not being compilable right now or if it's an actual issue. Any idea?
Thanks!
@tgalopin: Can you share a snippet of configure around line 5242? Please add ~50 lines above and below for additional context.
This should be produced after running phpize, which is what compiles config.m4 into configure.
For example, this is what I have locally (with added comments for context):
### PHP_ARG_ENABLE([mongodb-developer-flags], ...)
php_enable_mongodb_developer_flags=no
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to enable developer build flags" >&5
printf %s "checking whether to enable developer build flags... " >&6; }
# Check whether --enable-mongodb-developer-flags was given.
if test ${enable_mongodb_developer_flags+y}
then :
enableval=$enable_mongodb_developer_flags; PHP_MONGODB_DEVELOPER_FLAGS=$enableval
else $as_nop
PHP_MONGODB_DEVELOPER_FLAGS=no
fi
ext_output=$PHP_MONGODB_DEVELOPER_FLAGS
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ext_output" >&5
printf "%s\n" "$ext_output" >&6; }
### Literally from config.m4
if test "$PHP_MONGODB_DEVELOPER_FLAGS" = "yes"; then
### AX_CHECK_COMPILE_FLAG(-Wmissing-format-attribute, ...)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -Wmissing-format-attribute" >&5
printf %s "checking whether C compiler accepts -Wmissing-format-attribute... " >&6; }
if test ${ax_cv_check_cflags__Werror__Wmissing_format_attribute+y}
then :
printf %s "(cached) " >&6
else $as_nop
ax_check_save_flags=$CFLAGS
CFLAGS="$CFLAGS -Werror -Wmissing-format-attribute"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main (void)
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
ax_cv_check_cflags__Werror__Wmissing_format_attribute=yes
else $as_nop
ax_cv_check_cflags__Werror__Wmissing_format_attribute=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
CFLAGS=$ax_check_save_flags
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags__Werror__Wmissing_format_attribute" >&5
printf "%s\n" "$ax_cv_check_cflags__Werror__Wmissing_format_attribute" >&6; }
if test "x$ax_cv_check_cflags__Werror__Wmissing_format_attribute" = xyes
then :
_MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wmissing-format-attribute"
else $as_nop
:
fi
### AX_CHECK_COMPILE_FLAG(-Wduplicate-enum, ...)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -Wduplicate-enum" >&5
printf %s "checking whether C compiler accepts -Wduplicate-enum... " >&6; }
That output corresponds to the following in config.m4:
PHP_ARG_ENABLE([mongodb-developer-flags],
[whether to enable developer build flags],
[AS_HELP_STRING([--enable-mongodb-developer-flags],
[MongoDB: Enable developer flags [default=no]])],
[no],
[no])
if test "$PHP_MONGODB_DEVELOPER_FLAGS" = "yes"; then
dnl Warn about functions which might be candidates for format attributes
AX_CHECK_COMPILE_FLAG(-Wmissing-format-attribute, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wmissing-format-attribute" ,, -Werror)
dnl Avoid duplicating values for an enum
AX_CHECK_COMPILE_FLAG(-Wduplicate-enum, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wduplicate-enum" ,, -Werror)
@jmikola I am following these instructions to manually compile, and I have homebrew openssl@3 installed, but when I run ./configure --with-mongodb-ssl=openssl --with-openssl-dir=/opt/homebrew/include/openssl, I get this output
checking whether to enable crypto and TLS... openssl
checking deprecated option for OpenSSL library path... /opt/homebrew/include/openssl
checking for cc options needed to detect all undeclared functions... none needed
configure: checking whether OpenSSL is available
checking for openssl... no
checking for EVP_DigestInit_ex in -lcrypto... no
configure: checking whether OpenSSL >= 1.1.0 is available
checking for OPENSSL_init_ssl in -lssl... no
configure: checking whether OpenSSL < 1.1.0 is available
checking for SSL_library_init in -lssl... no
configure: error: OpenSSL libraries and development headers could not be found
I have verified that everything is installed, and openssl is being used for other packages. Is there something I'm doing wrong?
In my case, the issue was just that I didn't have pkg-config installed. Once I installed it via homebrew (brew install pkg-config), it went fine.
@sedwardsgt: Thanks for the feedback. I think the right call going forward is to simply require pkg-config when building the extension. The --with-openssl-dir option was ported from older versions of PHP, and I noted that logic doesn't even exist in PHP 7.4+ (PHP requires pkg-config itself). I'm not going to spend time investigating this, but my assumption is that the path searching logic was written with OpenSSL 1.x in mind and does not properly detect OpenSSL 3.x.
I've opened PHPC-2309 to track this.
@jmikola FWIW, I also have [email protected] installed, since it is apparently required by pickle, but my guess is it was looking for whatever is symlinked from /opt/homebrew/include/openssl (which happens to be /opt/homebrew/Cellar/openssl@3/3.1.3/include/openssl)
Okay I redid the whole thing just to be sure and have more details:
- I'm using PHP 5.6 on macOS (using https://github.com/shivammathur/homebrew-php) due to the app being a legacy we are upgrading
- I'm trying to connect to MongoDB Atlas in Cluster Mode: it works using a local Mongo but fails in non-cluster mode, I guess due to https://github.com/mongodb/mongo-php-driver/pull/1463 (and local Mongo not using SSL)
- Therefore I was trying to compile the 1.7.5 version of the driver on my mac, manually passing
--with-mongodb-ssl=opensslto it so that it could perhaps work locally
Maybe my idea can't work because this legacy version of the driver is not supported on the latest macOS?
I still reproduce the issue with a whole new setup:
./configure: line 5242: syntax error near unexpected token `-Wmissing-format-attribute,'
./configure: line 5242: ` AX_CHECK_COMPILE_FLAG(-Wmissing-format-attribute, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wmissing-format-attribute" ,, -Werror)'
@jmikola to answer your question, here are the lines around (with a manually added comment for line 5242):
if test "$PHP_MONGODB" != "no"; then
if test "$ac_cv_prog_cc_c99" = no; then
as_fn_error $? "Compiler does not support C99" "$LINENO" 5
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking PHP version" >&5
printf %s "checking PHP version... " >&6; }
if test -z "$PHP_CONFIG"; then
as_fn_error $? "php-config not found" "$LINENO" 5
fi
PHP_MONGODB_PHP_VERSION=`${PHP_CONFIG} --version`
PHP_MONGODB_PHP_VERSION_ID=`${PHP_CONFIG} --vernum`
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $PHP_MONGODB_PHP_VERSION" >&5
printf "%s\n" "$PHP_MONGODB_PHP_VERSION" >&6; }
if test "$PHP_MONGODB_PHP_VERSION_ID" -lt "70400"; then
as_fn_error $? "not supported. Need a PHP version >= 7.4.0 (found $PHP_MONGODB_PHP_VERSION)" "$LINENO" 5
fi
php_enable_mongodb_developer_flags=no
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to enable developer build flags" >&5
printf %s "checking whether to enable developer build flags... " >&6; }
# Check whether --enable-mongodb-developer-flags was given.
if test ${enable_mongodb_developer_flags+y}
then :
enableval=$enable_mongodb_developer_flags; PHP_MONGODB_DEVELOPER_FLAGS=$enableval
else $as_nop
PHP_MONGODB_DEVELOPER_FLAGS=no
fi
ext_output=$PHP_MONGODB_DEVELOPER_FLAGS
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ext_output" >&5
printf "%s\n" "$ext_output" >&6; }
if test "$PHP_MONGODB_DEVELOPER_FLAGS" = "yes"; then
# Line 5242:
AX_CHECK_COMPILE_FLAG(-Wmissing-format-attribute, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wmissing-format-attribute" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wduplicate-enum, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wduplicate-enum" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wheader-guard, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wheader-guard" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wlogical-not-parentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wlogical-not-parentheses" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wlogical-op, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wlogical-op" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-fsanitize-address, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fsanitize-address" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-fno-omit-frame-pointer, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fno-omit-frame-pointer" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-fno-optimize-sibling-calls, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fno-optimize-sibling-calls" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wlogical-op-parentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wlogical-op-parentheses" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wpointer-bool-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wpointer-bool-conversion" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wbool-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wbool-conversion" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wloop-analysis, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wloop-analysis" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wsizeof-array-argument, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wsizeof-array-argument" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wstring-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wstring-conversion" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wno-variadic-macros, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-variadic-macros" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wno-sign-compare, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-sign-compare" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-fstack-protector, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fstack-protector" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-fno-exceptions, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fno-exceptions" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wformat-security, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wformat-security" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wformat-nonliteral, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wformat-nonliteral" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Winit-self, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Winit-self" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wwrite-strings, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wwrite-strings" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wenum-compare, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wenum-compare" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wempty-body, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wempty-body" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wparentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wparentheses" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wmaybe-uninitialized, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wmaybe-uninitialized" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wimplicit-fallthrough, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wimplicit-fallthrough" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Werror, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Werror" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wextra, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wextra" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wno-unused-parameter, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-parameter" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wno-unused-but-set-variable, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-but-set-variable" ,, -Werror)
AX_CHECK_COMPILE_FLAG(-Wno-missing-field-initializers, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-missing-field-initializers",, -Werror)
if test "$PHP_MONGODB_PHP_VERSION_ID" -ge "80108"; then
AX_CHECK_COMPILE_FLAG(-Wstrict-prototypes, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wstrict-prototypes",, -Werror)
fi
MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS"
STD_CFLAGS="-g -O0 -Wall"
fi
php_enable_mongodb_coverage=no
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to enable code coverage" >&5
printf %s "checking whether to enable code coverage... " >&6; }
# Check whether --enable-mongodb-coverage was given.
if test ${enable_mongodb_coverage+y}
then :
enableval=$enable_mongodb_coverage; PHP_MONGODB_COVERAGE=$enableval
else $as_nop
PHP_MONGODB_COVERAGE=no
fi
PHP 7.2 introduced the AX_CHECK_COMPILE_FLAG macro in https://github.com/php/php-src/commit/086f9adc4d6fe58b75e419cd6312afdbf3d90277. That was later backported into PHP 7.1.2+ and 7.0.16+ in https://github.com/php/php-src/commit/699ab98f9db9a57f3d352b9dc3b1558a6ef55930 (see later comments in https://github.com/php/php-src/pull/2124).
In https://github.com/mongodb/mongo-php-driver/commit/d785d5e15e826f20b73c804e5ad3c8fb351f6a06 (released in 1.9.0), we replaced the old PHP_CHECK_GCC_ARG macro in config.m4 with AX_CHECK_COMPILE_FLAG. Version 1.9.0 of this extension also advertised compatibility with PHP 7.0+, which technically would not have been true; however, I don't believe PECL provides any way to define distinct requirements for different minor versions of PHP. Ideally, we would have required 7.0.16+ and 7.1.2+.
AX_CHECK_COMPILE_FLAG would be undefined on earlier PHP versions before 7.0.16 and 7.1.2. I'm not certain, but I think that would result in phpize ignoring the macro entirely, which would explain how it ends up in the configure script.
That said, you also mentioned building extension version 1.7.5, which predates the introduction of this macro in https://github.com/mongodb/mongo-php-driver/commit/d785d5e15e826f20b73c804e5ad3c8fb351f6a06 (1.9.0), so I'm not sure what to make of that.
I'm not sure what version of MongoDB you're using in Atlas, but note that version 1.7.5 of the driver was only ever tested with MongoDB 4.2 (see: compatibility tables managed by our docs team). There is no guarantee that it will work for newer server versions. I'm also not in any position to help diagnose build errors for such an old version on the driver with PHP 5.6.
PHP-2280 and the original issue that prompted it (https://github.com/mongodb/mongo-php-library/issues/1145) pertained to macOS 13+. Older versions of the driver (and even libmongoc) would never have been tested with that, and it's quite possible there are other incompatibilities.
If you're obligated to use PHP 5.6, I think the best approach would be to try and get something running in Docker where you have more control over all of the shared libraries (including OpenSSL). Assuming the container is a Linux host, that would also entirely sidestep the issue of the driver preferring Secure Transport during its build process.