Error when build mongo-c-driver with visual studio 2019

Hello, I’m new to MongoDB, and I’m trying to build the mongo-c-driver, the version is 1.25.0. However, some errors are appears in the build process. The CMake output and the Visual Studio 2019 error output are shown below.
CMAKE:
Found Python: D:/anaconda3/python.exe (found version “3.11.5”) found components: Interpreter
Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19045.
The C compiler identification is MSVC 19.29.30154.0
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
Detecting C compile features
Detecting C compile features - done
Performing Test CMAKE_HAVE_LIBC_PTHREAD
Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
Looking for pthread_create in pthreads
Looking for pthread_create in pthreads - not found
Looking for pthread_create in pthread
Looking for pthread_create in pthread - not found
Found Threads: TRUE
Looking for a CXX compiler
Looking for a CXX compiler - C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
The CXX compiler identification is MSVC 19.29.30154.0
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
Detecting CXX compile features
Detecting CXX compile features - done
Found Python3: D:/anaconda3/python.exe (found version “3.11.5”) found components: Interpreter
Using bundled libbson
Looking for snprintf
Looking for snprintf - found
Performing Test BSON_HAVE_TIMESPEC
Performing Test BSON_HAVE_TIMESPEC - Success
Looking for gmtime_r
Looking for gmtime_r - not found
Looking for rand_r
Looking for rand_r - not found
Looking for strings.h
Looking for strings.h - not found
Looking for strlcpy
Looking for strlcpy - not found
Looking for stdbool.h
Looking for stdbool.h - found
Looking for clock_gettime
Looking for clock_gettime - not found
Looking for strnlen
Looking for strnlen - found
Looking for sched_getcpu
Looking for sched_getcpu - not found
libmongoc version (from VERSION_CURRENT file): 1.25.0
Enabling zlib compression (bundled)
Looking for include file unistd.h
Looking for include file unistd.h - not found
Looking for include file stdarg.h
Looking for include file stdarg.h - found
Searching for compression library zstd
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Not found
libmongoc TLS : SecureChannel
Using SASL backend : SSPI
Looking for sys/types.h
Looking for sys/types.h - found
Looking for stdint.h
Looking for stdint.h - found
Looking for stddef.h
Looking for stddef.h - found
Check size of socklen_t
Check size of socklen_t - done
Searching for compression library header snappy-c.h
Found in D:/anaconda3/Library/include
Searching for libsnappy
Found D:/anaconda3/Library/lib/snappy.lib
Searching for libmongocrypt
libmongocrypt not found. Configuring without Client-Side Field Level Encryption support.
Performing Test MONGOC_HAVE_SS_FAMILY
Performing Test MONGOC_HAVE_SS_FAMILY - Failed
Compiling against Windows SSPI
Enabling utf8proc (bundled)
Building with MONGODB-AWS auth support
Build files generated for:
build system: Visual Studio 16 2019
instance: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional
instance: x64
The following features have been enabled:

  • TLS, for secure network communication (SecureChannel)
  • Cryptography, cryptographic primitives (SecureChannel)
  • AWS Authentication, authenticate with MongoDB servers using credentials from AWS instance metadata
  • SASL Authentication, authenticate with MongoDB servers using SASL: “Simple Authentication and Security Layer” (SSPI)

Configuring done (17.0s)
Generating done (2.3s)

Visual Studio 2019 errors:

|Error|C2065|‘_bsonDSL_Type_int’: undeclared identifier|mongoc_shared|E:\mongo-c-driver-src\src\libmongoc\src\mongoc\mongoc-uri.c|1784||

|Error|C4013|‘_bsonVisitIterAs_int’ undefined; assuming extern returning int|mongoc_static|E:\mongo-c-driver-src\src\libmongoc\src\mongoc\mongoc-uri.c|1779||

Can anyone help me fix it ? Thanks.

What cmake commands are run? I was unable to reproduce. The following Powershell commands worked for me:

# Define path to CMake:
$cmake='C:\Program Files\CMake\bin\cmake.exe'
# Get C driver 1.25.0:
git clone https://github.com/mongodb/mongo-c-driver --branch 1.25.0
cd mongo-c-driver
# Configure:
& "$cmake" -G "Visual Studio 16 2019" -A x64 `
    -DCMAKE_INSTALL_PREFIX="C:\mongo-c-driver-1.25.0" `
    -S. -Bcmake-build
# Build and install:
& "$cmake" --build cmake-build --target INSTALL
1 Like

The cmake commands used are same. I rerun the commands again, Cmake configuration completed, but when run build, error still remains. The errors appears in source file “mongoc-util.c”. Is there some dependencies missed install in my environment?

Errors:

C:\Users\Administrator\Desktop\test\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-uri.c(1784,1): error C2065: “_bsonDS
L_Type_int”: undeclared identifier [C:\Users\Administrator\Desktop\test\mongo-c-driver\cmake-build\src\libmongoc\mongoc_static.vcxpro
j]
C:\Users\Administrator\Desktop\test\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-uri.c(1779,1): error C4013: “_bsonVi
sitIterAs_int”undefined; assuming extern returning int [C:\Users\Administrator\Desktop\test\mongo-c-driver\cmake-build\src\libmongoc\mongoc_stati
c.vcxproj]
C:\Users\Administrator\Desktop\test\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-uri.c(1804,1): error C2065: “_bsonDS
L_Type_int”: undeclared identifier [C:\Users\Administrator\Desktop\test\mongo-c-driver\cmake-build\src\libmongoc\mongoc_static.vcxpro
j]
mongoc-util.c

Idea: I expect something is defining bool or _Bool as a macro evaluating to int. This issue has been reported in CDRIVER-5629. I can reproduce the error if I manually add a #define bool int around the code causing the error.

The contents of stdbool.h in my install defines bool as _Bool (in path C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\stdbool.h):

#define bool _Bool

Does stdbool.h on your machine differ? Or is something else possibly defining bool or _Bool as an int?

1 Like