Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nmake on windows cmd is throwing error when compiling mongodb extension with php-src #1767

Open
aravindjayanthi98 opened this issue Jan 16, 2025 · 3 comments

Comments

@aravindjayanthi98
Copy link

Bug Report

Environment

OS: Windows servercore 2022
PHP: 8.4.2 (using source code), NTS, x64
MongoDB extension: 1.20.1 (Downloaded from pecl repository)

Test Script

I am using Docker to compile and build the php along with some extensions. I have followed the steps mentioned in this page. As per the mongodb installation script, I have used the following commands:

WORKDIR /php-sdk/phpdev/vs${VS_VERSION}/${ARCH}/php-${PHP_VERSION}-src/ext
ADD https://pecl.php.net/get/mongodb-1.20.1.tgz ./mongodb.tgz
RUN tar xzf ./mongodb.tgz && del .\mongodb.tgz && move ./package.xml ./mongodb-1.20.1/ && ren mongodb-1.20.1 mongodb
# download dependencies using phpsdk_deps and run buildconf
RUN configure --with-openssl --enable-mongodb=shared 

I have added other configure options as well, if I don't make the mongodb shared, the configure is failing with the message "Static mongodb can not depend on shared openssl".

Error

With the shared option enabled in the configure command, I resolved the above mentioned error but when running nmake command I am getting the following error:

mongoc-cyrus.c
ext\mongodb\src\libmongoc\src\libmongoc\src\mongoc\mongoc-cyrus.c(157): error C2065: 'MONGOC_CYRUS_PLUGIN_PATH_PREFIX': undeclared identifier
ext\mongodb\src\libmongoc\src\libmongoc\src\mongoc\mongoc-cyrus.c(157): warning C4047: 'initializing': 'const char *' differs in levels of indirection from 'int'
NMAKE : fatal error U1077: '"cl.exe" /D ZEND_COMPILE_DL_EXT=1 /D COMPILE_DL_MONGODB /D MONGODB_EXPORTS=1 /D BSON_COMPILATION /D MONGOC_COMPILATION /D UTF8PROC_STATIC /Iext\mongodb /Iext\mongodb/src /Iext\mongodb/src/BSON /Iext\mongodb/src/MongoDB /Iext\mongodb/src/MongoDB/Exception /Iext\mongodb/src/MongoDB/Monitoring /Iext\mongodb/src/contrib /Iext\mongodb/src/libmongoc/src/common /Iext\mongodb/src/libmongoc/src/uthash /Iext\mongodb/src/libmongoc/src/libbson/src /Iext\mongodb/src/libmongoc/src/libbson/src/jsonsl /Iext\mongodb/src/libmongoc/src/libmongoc/src /Iext\mongodb/src/libmongoc/src/libmongoc/src/mongoc /Iext\mongodb/src/libmongoc/src/utf8proc-2.8.0 /I "..\deps\include" /DHAVE_OPENSSL_SSL_H=1 /D KMS_MSG_STATIC=1 /D KMS_MESSAGE_ENABLE_CRYPTO=1 /D KMS_MESSAGE_ENABLE_CRYPTO_LIBCRYPTO=1 /DHAVE_SASL_SASL_H=1 /D KMS_MESSAGE_LITTLE_ENDIAN=1 /D MONGOCRYPT_LITTLE_ENDIAN=1 /D MLIB_USER=1 /Iext\mongodb/src/libmongocrypt/src /Iext\mongodb/src/libmongocrypt/kms-message/src /Iext\mongodb/src/libmongocrypt-compat /DHAVE_WINDNS_H=1 /nologo /I . /I main /I Zend /I TSRM /I ext /D _WINDOWS /D WINDOWS=1 /D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _MBCS /D _USE_MATH_DEFINES /FD /wd4996 /RTC1 /Zc:__cplusplus /d2FuncCache1 /Zc:preprocessor /Zc:wchar_t /LDd /MDd /Od /D _DEBUG /D ZEND_DEBUG=1 /Zi /I "..\deps\include" /D FD_SETSIZE=256 /FpC:\php\Debug/src/libmongoc/src/libmongoc/src/mongoc\ /FRC:\php\Debug/src/libmongoc/src/libmongoc/src/mongoc\ /FdC:\php\Debug/src/libmongoc/src/libmongoc/src/mongoc\ /c ext\mongodb\src\libmongoc\src\libmongoc\src\mongoc\mongoc-cyrus.c /FoC:\php\Debug/src/libmongoc/src/libmongoc/src/mongoc\mongoc-cyrus.obj' : return code '0x2'
Stop.
The command 'cmd /S /C configure --enable-object-out-dir=%PHP_OUT_DIR% --with-php-build=..\deps %PHP_PARAMETERS% --enable-mongodb=shared && nmake' returned a non-zero code: 2

The last command nmake ran before the above error is:
"cl.exe" /D ZEND_COMPILE_DL_EXT=1 /D COMPILE_DL_MONGODB /D MONGODB_EXPORTS=1 /D BSON_COMPILATION /D MONGOC_COMPILATION /D UTF8PROC_STATIC /Iext\mongodb /Iext\mongodb/src /Iext\mongodb/src/BSON /Iext\mongodb/src/MongoDB /Iext\mongodb/src/MongoDB/Exception /Iext\mongodb/src/MongoDB/Monitoring /Iext\mongodb/src/contrib /Iext\mongodb/src/libmongoc/src/common /Iext\mongodb/src/libmongoc/src/uthash /Iext\mongodb/src/libmongoc/src/libbson/src /Iext\mongodb/src/libmongoc/src/libbson/src/jsonsl /Iext\mongodb/src/libmongoc/src/libmongoc/src /Iext\mongodb/src/libmongoc/src/libmongoc/src/mongoc /Iext\mongodb/src/libmongoc/src/utf8proc-2.8.0 /I "..\deps\include" /DHAVE_OPENSSL_SSL_H=1 /D KMS_MSG_STATIC=1 /D KMS_MESSAGE_ENABLE_CRYPTO=1 /D KMS_MESSAGE_ENABLE_CRYPTO_LIBCRYPTO=1 /DHAVE_SASL_SASL_H=1 /D KMS_MESSAGE_LITTLE_ENDIAN=1 /D MONGOCRYPT_LITTLE_ENDIAN=1 /D MLIB_USER=1 /Iext\mongodb/src/libmongocrypt/src /Iext\mongodb/src/libmongocrypt/kms-message/src /Iext\mongodb/src/libmongocrypt-compat /DHAVE_WINDNS_H=1 /nologo /I . /I main /I Zend /I TSRM /I ext /D _WINDOWS /D WINDOWS=1 /D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _MBCS /D _USE_MATH_DEFINES /FD /wd4996 /RTC1 /Zc:__cplusplus /d2FuncCache1 /Zc:preprocessor /Zc:wchar_t /LDd /MDd /Od /D _DEBUG /D ZEND_DEBUG=1 /Zi /I "..\deps\include" /D FD_SETSIZE=256 /FpC:\php\Debug\/src/libmongoc/src/libmongoc/src/mongoc\ /FRC:\php\Debug\/src/libmongoc/src/libmongoc/src/mongoc\ /FdC:\php\Debug\/src/libmongoc/src/libmongoc/src/mongoc\ /c ext\mongodb\src\libmongoc\src\libmongoc\src\mongoc\mongoc-cyrus.c /FoC:\php\Debug\/src/libmongoc/src/libmongoc/src/mongoc\mongoc-cyrus.obj

Can someone please help me with this issue?

@jmikola
Copy link
Member

jmikola commented Jan 16, 2025

The second build errors seem to be caused by MONGOC_CYRUS_PLUGIN_PATH_PREFIX being undefined. I determined that the constant was introduced in libmongoc 1.26.2 (mongodb/mongo-c-driver@0e771ca) but never added to config.w32 when the PHP driver bumped its libmongoc dependency in the 1.18.1 release (6a2e15a).

I've opened PHPC-2501 to track this.

In the meantime, you can see if configuring the build with --with-mongodb-sasl=no would unblock you by skipping compilation of mongoc-cyrus.c. Alternatively, consider using a pre-compiled DLL as advised in the install docs for Windows.

@aravindjayanthi98
Copy link
Author

Thank you very much @jmikola , the issue got resolved once I added the --without-mongodb-sasl flag. Now, I can see mongodb in the list of extensions available.
I'll keep track of the issue opened and remove the flag (and update the version) once its resolved.

Since I am doing the compilation of extensions along with php-src code, I keep getting the following error if I directly add the DLL files after the compilation is done:

Warning: PHP Startup: Unable to load dynamic library 'mongodb' (tried: C:\php\Debug\mongodb (The specified module could not be found), C:\php\Debug\php_mongodb.dll (The specified module could not be found)) in Unknown on line 0

I did check my environment thrice and I am sure that I have downloaded the right version of DLL files. Is there any way I could resolve this issue? because if I can use DLLs directly it would save a ton of time as I am facing this issue for other extensions also.

@jmikola
Copy link
Member

jmikola commented Jan 17, 2025

Loading an Incompatible DLL on Windows in the library FAQ may help you diagnose the DLL issue. It references a detect-extension.php script that produces a report on the PHP environment in which you run it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants