[CDRIVER-3082] Build error on MSYS2 Created: 12/Apr/19  Updated: 28/Oct/23  Resolved: 22/May/19

Status: Closed
Project: C Driver
Component/s: docs, libbson, libmongoc
Affects Version/s: 1.14.0
Fix Version/s: 1.15.0

Type: Bug Priority: Major - P3
Reporter: Felipe Noronha Tavares Assignee: Kevin Albertson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MSYS2, Windows 10



 Description   

I'm following the instructions on http://mongoc.org/libmongoc/current/installing.html#building-on-windows-with-mingw-w64-and-msys2  . 

 

First, I had to use a single dot `.` at the end of the command, as the docs instruct to untar and enter the source code directory.

 

```

$ CC=/mingw64/bin/gcc.exe /mingw64/bin/cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX="D:/install" .

```

 

The cmake build starts, but than it fails with these messages:

 

```

fnoro@N-00933732 MINGW64 /d/src/mongo-c-driver
$ make
Scanning dependencies of target bson_shared
[ 0%] Building C object src/libbson/CMakeFiles/bson_shared.dir/src/bson/bcon.c.obj
In file included from D:/src/mongo-c-driver/src/libbson/src/bson/bson.h:23,
from D:/src/mongo-c-driver/src/libbson/src/bson/bcon.h:26,
from D:/src/mongo-c-driver/src/libbson/src/bson/bcon.c:24:
D:/src/mongo-c-driver/src/libbson/src/bson/bson-compat.h:27:2: error: #error "__USE_MINGW_ANSI_STDIO > 0 is required for correct PRI* macros"
#error "__USE_MINGW_ANSI_STDIO > 0 is required for correct PRI* macros"
^~~~~
make[2]: *** [src/libbson/CMakeFiles/bson_shared.dir/build.make:63: src/libbson/CMakeFiles/bson_shared.dir/src/bson/bcon.c.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:219: src/libbson/CMakeFiles/bson_shared.dir/all] Error 2
make: *** [Makefile:152: all] Error 2

```



 Comments   
Comment by Kevin Albertson [ 22/May/19 ]

Hi felipenoris, the documentation for building on MSYS2 has been updated after reproducing and verifying that the new steps work. Please feel free to re-open if this does not resolve the issue for you.

Comment by Githook User [ 22/May/19 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}

Message: CDRIVER-3082 fix install docs for msys2
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/3a806bba4e703138aefa51db31c9e71035d439a0

Comment by Kevin Albertson [ 20/May/19 ]

I've reproduced and confirmed that defining the additional C flag fixes this issue.

Comment by Kevin Albertson [ 20/May/19 ]

Hi felipenoris! Apologies for the late reply. And... I misread, the macro has two underscores. Try again with:

-DCMAKE_C_FLAGS="-D__USE_MINGW_ANSI_STDIO=1" 

I will attempt to reproduce and update our documentation accordingly. Sorry for the confusion.

Comment by Felipe Noronha Tavares [ 23/Apr/19 ]

Thanks for helping!

Defining -DCMAKE_C_FLAGS="-D_USE_MINGW_ANSI_STDIO=1" has no effect on the outcome.

The verbose build output is this below.

```
$ make
/D/local/msys2/mingw64/bin/cmake.exe -S/D/local/src/mongo-c-driver-1.14.0 -B/D/local/src/mongo-c-driver-1.14.0 --check-build-system CMakeFiles/Makefile.cmake 0
/D/local/msys2/mingw64/bin/cmake.exe -E cmake_progress_start /D/local/src/mongo-c-driver-1.14.0/CMakeFiles /D/local/src/mongo-c-driver-1.14.0/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/d/local/src/mongo-c-driver-1.14.0'
make -f src/libbson/CMakeFiles/bson_shared.dir/build.make src/libbson/CMakeFiles/bson_shared.dir/depend
make[2]: Entering directory '/d/local/src/mongo-c-driver-1.14.0'
/D/local/msys2/mingw64/bin/cmake.exe -E cmake_depends "MSYS Makefiles" /D/local/src/mongo-c-driver-1.14.0 /D/local/src/mongo-c-driver-1.14.0/src/libbson /D/local/src/mongo-c-driver-1.14.0 /D/local/src/mongo-c-driver-1.14.0/src/libbson /D/local/src/mongo-c-driver-1.14.0/src/libbson/CMakeFiles/bson_shared.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/d/local/src/mongo-c-driver-1.14.0'
make -f src/libbson/CMakeFiles/bson_shared.dir/build.make src/libbson/CMakeFiles/bson_shared.dir/build
make[2]: Entering directory '/d/local/src/mongo-c-driver-1.14.0'
[ 0%] Building C object src/libbson/CMakeFiles/bson_shared.dir/src/bson/bcon.c.obj
cd /D/local/src/mongo-c-driver-1.14.0/src/libbson && /D/local/msys2/mingw64/bin/gcc.exe -DBSON_COMPILATION -DJSONSL_PARSE_NAN -Dbson_shared_EXPORTS -I/D/local/src/mongo-c-driver-1.14.0/src/libbson/src -I/D/local/src/mongo-c-driver-1.14.0/src/libbson/../../src/common -D_USE_MINGW_ANSI_STDIO=1 -O2 -g -DNDEBUG -o CMakeFiles/bson_shared.dir/src/bson/bcon.c.obj -c /D/local/src/mongo-c-driver-1.14.0/src/libbson/src/bson/bcon.c
In file included from D:/local/src/mongo-c-driver-1.14.0/src/libbson/src/bson/bson.h:23,
from D:/local/src/mongo-c-driver-1.14.0/src/libbson/src/bson/bcon.h:26,
from D:/local/src/mongo-c-driver-1.14.0/src/libbson/src/bson/bcon.c:24:
D:/local/src/mongo-c-driver-1.14.0/src/libbson/src/bson/bson-compat.h:27:2: error: #error "__USE_MINGW_ANSI_STDIO > 0 is required for correct PRI* macros"
#error "__USE_MINGW_ANSI_STDIO > 0 is required for correct PRI* macros"
^~~~~
make[2]: *** [src/libbson/CMakeFiles/bson_shared.dir/build.make:66: src/libbson/CMakeFiles/bson_shared.dir/src/bson/bcon.c.obj] Error 1
make[2]: Leaving directory '/d/local/src/mongo-c-driver-1.14.0'
make[1]: *** [CMakeFiles/Makefile2:222: src/libbson/CMakeFiles/bson_shared.dir/all] Error 2
make[1]: Leaving directory '/d/local/src/mongo-c-driver-1.14.0'
make: *** [Makefile:155: all] Error 2
```

Comment by Kevin Albertson [ 15/Apr/19 ]

Hi felipenoris. Thank you for the report. I have not yet had a chance to attempt to reproduce, but that error is triggered by _USE_MINGW_ANSI_STDIO being defined as 0. This define controls compatibility of printf formats.

I'm not sure where it would be defined, but perhaps try defining it yourself in the cmake config:

CC=/mingw64/bin/gcc.exe /mingw64/bin/cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX="D:/install" -DCMAKE_C_FLAGS="-D_USE_MINGW_ANSI_STDIO=1" .

If that does not solve the issue, can you try running cmake with verbosity turned on and copying the output of make here? (-DCMAKE_VERBOSE_MAKEFILE=ON):

CC=/mingw64/bin/gcc.exe /mingw64/bin/cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX="D:/install" -DCMAKE_VERBOSE_MAKEFILE=ON .

That should give more information, and might indicate where it's getting defined.

Comment by Felipe Noronha Tavares [ 12/Apr/19 ]

As additional information, this is the output of the first command, just before typing `make`.
 
```
$ CC=/mingw64/bin/gcc.exe /mingw64/bin/cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX="D:/install" .
– No CMAKE_BUILD_TYPE selected, defaulting to RelWithDebInfo
file VERSION_CURRENT contained BUILD_VERSION 0.0.0
– Using bundled libbson
libbson version (from VERSION_CURRENT file): 0.0.0
– struct timespec found
libmongoc version (from VERSION_CURRENT file): 0.0.0
– Searching for zlib CMake packages
– zlib found version "1.2.11"
– zlib include path "D:/local/msys2/mingw64/include"
– zlib libraries "D:/local/msys2/mingw64/lib/libz.dll.a"
– Searching for compression library header snappy-c.h
– Not found (specify -DCMAKE_INCLUDE_PATH=/path/to/snappy/include for Snappy compression)
– No ICU library found, SASLPrep disabled for SCRAM-SHA-256 authentication.
– If ICU is installed in a non-standard directory, define ICU_ROOT as the ICU installation path.
– Compiling against Secure Channel
– Compiling against Windows SSPI
– Configuring done
– Generating done
– Build files have been written to: D:/src/mongo-c-driver
```
 

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