[CDRIVER-2157] Linking to libmongoc with MinGW-64 fails to find crypt32.lib Created: 09/May/17  Updated: 28/Oct/23  Resolved: 20/Jun/17

Status: Closed
Project: C Driver
Component/s: Build, libmongoc, mingw
Affects Version/s: 1.7.0
Fix Version/s: 1.7.0

Type: Bug Priority: Major - P3
Reporter: Gustavo Brondani Schenkel Assignee: A. Jesse Jiryu Davis
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Environment x86_64
MSYS2 - 2.7.0
GCC - 6.3.0
CMake - 3.7.2
Boost - 1.63.0
libbson - git master(09/05)
libmongoc - git master(09/05)


Attachments: Text File gcc log.txt     File libmongoc-1.0-config-version.cmake     File libmongoc-1.0-config.cmake     File libmongoc-1.0.pc     File libmongoc-ssl-1.0.pc     File libmongoc-static-1.0-config-version.cmake     File libmongoc-static-1.0-config.cmake     File libmongoc-static-1.0.pc    
Issue Links:
Depends
Related
related to CDRIVER-2074 Convenient usage as a static library Closed
related to CDRIVER-2083 Distribute CMake config packages for ... Closed

 Description   

When mongo-c-driver is built against openssl+cyrus, the pkg-config files get broken.
Compiling any code using pkg-config gets the message "gcc.exe: error: crypt32.lib: No such file or directory".
Compiling a program without pkg-config works.
Compiling a program with pkg-config and with mongo-c-driver built without any SSL+SASL works too.

Appears pkg-config file is trying to find files from WINDOWS + SSPI build info.

Using the following command to build from inside 'build' folder:
cmake -DENABLE_SSL=OPENSSL -DENABLE_SASL=CYRUS -DCMAKE_INSTALL_PREFIX=/mingw64 -G "CodeBlocks - MinGW Makefiles" ..



 Comments   
Comment by Githook User [ 20/Jun/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-2157 link a sample program with MinGW-64
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/756e9e18bfe85e062883299d26e229d0d81b586f

Comment by Gustavo Brondani Schenkel [ 19/May/17 ]

Sorry about the delay, I didn't see the e-mail notification until afternoon.
I built this one with the last changes from master, and against the last from libbson.

Comment by A. Jesse Jiryu Davis [ 18/May/17 ]

I have a script in progress that will test this path in Evergreen.

Comment by A. Jesse Jiryu Davis [ 18/May/17 ]

With the current code, I can't actually build with "-DENABLE_SASL=CYRUS", I get errors compiling mongoc-cluster-sasl.c:

In file included from C:\data\mci\source-mongo-c-driver-cfaac7\build-dir\src\mongoc\mongoc-cluster-sasl.c:21:0:
c:/sasl/include/sasl/sasl.h:228:1: warning: parameter names (without types) in function declaration
 typedef void *sasl_malloc_t(size_t);
 ^
c:/sasl/include/sasl/sasl.h:229:1: warning: parameter names (without types) in function declaration
 typedef void *sasl_calloc_t(size_t, size_t);
 ^
c:/sasl/include/sasl/sasl.h:230:38: error: unknown type name 'size_t'
 typedef void *sasl_realloc_t(void *, size_t);
                                      ^
c:/sasl/include/sasl/sasl.h:235:5: error: unknown type name 'sasl_realloc_t'
     sasl_realloc_t *,
     ^

This is easily fixed by including bson.h before sasl.h, to ensure that size_t is defined.

Now, the CMake-generated libmongoc-1.0.pc has:

Libs: -L${libdir} -lmongoc-1.0  -Lc:/sasl/lib -lsasl2 -LC:/openssl/lib -lssleay32 -LC:/openssl/lib -leay32 crypt32.lib
Cflags: -I${includedir}/libmongoc-1.0

Comment by A. Jesse Jiryu Davis [ 17/May/17 ]

Assigning to myself for now. I'm going to add a test for this path in Evergreen: build the driver with CMake and MinGW-64, link an example program to it using pkg-config.

Comment by David Golden [ 17/May/17 ]

Hello, gbschenkel. Could you please attach all the .pc and .cmake files that were installed when you build the C driver?
Thanks!

Comment by Gustavo Brondani Schenkel [ 11/May/17 ]

I really don't know if I am missing something or not but, I got one more error with GCC + pkg-config, I saved the report in gcc log.txt.
Compiling using mongo-c-driver/examples/cmake/find_package_static works fine.

Comment by David Golden [ 10/May/17 ]

OK. Thanks for that extra information. I'm away from the office this week, but when I'm back, I'm going to try to reproduce this and see exactly when we do and don't need that library in the .pc/.cmake files for MSVC and MinGW. Even with MinGW and OpenSSL, we use that on Windows to access the system CA store so I want to make sure that's working.

Comment by Gustavo Brondani Schenkel [ 10/May/17 ]

I built again but before install the driver, I edited the libmongoc-1.0.pc and libmongoc-static-1.0.pc and removed the crypt32.lib reference and it stopped of ask the lib.

I think the reference it been inserted from CMakeLists.txt at lines 462 and 463. Since MSYS2 use a Unix-like environment but run as native WIN32, I think the condition is been accepted as true, and the lib is been inserted inside the .cp files.

Comment by Gustavo Brondani Schenkel [ 10/May/17 ]

Hi, I used the script from examples/cmake, for both shared and static, and the compile works as expected.
It seems only using gcc -o hello hello_mongoc.c $(pkg-config --cflags --libs libmongoc-1.0) rise the error: gcc.exe: error: crypt32.lib: No such file or directory.

PS: sorry about the crap issue's title, forgot to complete it before inserting.

Comment by David Golden [ 10/May/17 ]

Hi. If you compile your own code with CMake, does it work?

Comment by Gustavo Brondani Schenkel [ 10/May/17 ]

Hi, I compile against version 1.6.2 and pkg-config worked just fine. Appears is something on master. I noticed this issue because I was getting the same error trying to compile a code with mongo-cxx-driver static lib.

Comment by Hannes Magnusson [ 09/May/17 ]

Is this only an issue in current master? Or have you reproduced this in our last release (1.6.2?)

Generated at Wed Feb 07 21:14:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.