Mongo-c-driver-1.23.0 build error on Ubuntu 18.04

I’ve encountered a build error following the instructions at Installing the MongoDB C Driver (libmongoc) and BSON library (libbson) — libmongoc 1.23.2
for version 1.23.0. The flag -Werror is set and as a result the build fails here:

[ 77%] Building C object src/libmongoc/CMakeFiles/test-libmongoc.dir/tests/test-mongoc-client.c.o
/home/xxx/Mongodb/mongo-c-driver-1.23.0/src/libmongoc/tests/test-mongoc-client.c: In function ‘_test_client_sends_handshake’:
/home/xxx/Mongodb/mongo-c-driver-1.23.0/src/libmongoc/tests/test-mongoc-client.c:3377:7: error: ‘pool’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
       mongoc_client_pool_destroy (pool);
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/xxx/Mongodb/mongo-c-driver-1.23.0/src/libmongoc/tests/test-mongoc-client.c:3354:7: error: ‘future’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
       future_destroy (future);
       ^~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
src/libmongoc/CMakeFiles/test-libmongoc.dir/build.make:1238: recipe for target 'src/libmongoc/CMakeFiles/test-libmongoc.dir/tests/test-mongoc-client.c.o' failed
make[2]: *** [src/libmongoc/CMakeFiles/test-libmongoc.dir/tests/test-mongoc-client.c.o] Error 1
CMakeFiles/Makefile2:2506: recipe for target 'src/libmongoc/CMakeFiles/test-libmongoc.dir/all' failed
make[1]: *** [src/libmongoc/CMakeFiles/test-libmongoc.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

I can get by this by editing the CMake files and removing the -Werror but presumably that is there by design.

CMake output follows:

mymachine:~/Downloads/Mongodb/mongo-c-driver-1.23.0/cmake-build$ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DCMAKE_BUILD_TYPE=Release ..
-- The C compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for a CXX compiler
-- Looking for a CXX compiler - /usr/bin/c++
-- The CXX compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
file VERSION_CURRENT contained BUILD_VERSION 1.23.0
-- Build and install static libraries
  -- Using bundled libbson
libbson version (from VERSION_CURRENT file): 1.23.0
-- Check if the system is big endian
-- Searching 16 bit integer
-- 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 unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Looking for snprintf
-- Looking for snprintf - found
-- Performing Test BSON_HAVE_TIMESPEC
-- Performing Test BSON_HAVE_TIMESPEC - Success
--     struct timespec found
-- Looking for gmtime_r
-- Looking for gmtime_r - found
-- Looking for rand_r
-- Looking for rand_r - found
-- Looking for strings.h
-- Looking for strings.h - 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 - found
-- Looking for strnlen
-- Looking for strnlen - found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE  
Adding -fPIC to compilation of bson_static components
libmongoc version (from VERSION_CURRENT file): 1.23.0
-- Searching for zlib CMake packages
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") 
--   zlib found version "1.2.11"
--   zlib include path "/usr/include"
--   zlib libraries "/usr/lib/x86_64-linux-gnu/libz.so"
-- Looking for include file unistd.h
-- Looking for include file unistd.h - found
-- Looking for include file stdarg.h
-- Looking for include file stdarg.h - found
-- Searching for compression library zstd
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Checking for module 'libzstd'
--   No package 'libzstd' found
--   Not found
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1") 
-- Looking for ASN1_STRING_get0_data in /usr/lib/x86_64-linux-gnu/libcrypto.so
-- Looking for ASN1_STRING_get0_data in /usr/lib/x86_64-linux-gnu/libcrypto.so - found
-- Searching for sasl/sasl.h
--   Found in /usr/include
-- Searching for libsasl2
--   Found /usr/lib/x86_64-linux-gnu/libsasl2.so
-- Looking for sasl_client_done
-- Looking for sasl_client_done - found
-- Check size of socklen_t
-- Check size of socklen_t - done
-- Looking for res_nsearch
-- Looking for res_nsearch - found
-- Looking for res_ndestroy
-- Looking for res_ndestroy - not found
-- Looking for res_nclose
-- Looking for res_nclose - found
-- Looking for sched_getcpu
-- Looking for sched_getcpu - not found
-- Detected parameters: accept (int, struct sockaddr *, socklen_t *)
-- Searching for compression library header snappy-c.h
--   Not found (specify -DCMAKE_INCLUDE_PATH=/path/to/snappy/include for Snappy compression)
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 - Success
-- Compiling against OpenSSL
-- Compiling against Cyrus SASL
Adding -fPIC to compilation of mongoc_static components
-- Building with MONGODB-AWS auth support
-- Build files generated for:
-- 	build system: Unix Makefiles
-- Configuring done
-- Generating done
-- Build files have been written to: /home/xxx/Mongodb/mongo-c-driver-1.23.0/cmake-build

You can file an issue here

Thank you. I’ll try that.

1 Like