@Roberto_Sanchez OS is Ubuntu 18.04 I’ve configured the C driver build with this command:
$ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DCMAKE_BUILD_TYPE=Release ..
getting this result:
-- The C compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
file VERSION_CURRENT contained BUILD_VERSION 1.17.3
-- Build and install static libraries
-- Using bundled libbson
libbson version (from VERSION_CURRENT file): 1.17.3
-- 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
-- Searching 16 bit integer - Using unsigned short
-- Check if the system is big endian - little endian
-- Looking for snprintf
-- Looking for snprintf - found
-- Looking for reallocf
-- Looking for reallocf - not 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
CMake Warning (dev) at /snap/cmake/769/share/cmake-3.19/Modules/CheckIncludeFile.cmake:80 (message):
Policy CMP0075 is not set: Include file check macros honor
CMAKE_REQUIRED_LIBRARIES. Run "cmake --help-policy CMP0075" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
CMAKE_REQUIRED_LIBRARIES is set to:
/usr/lib/x86_64-linux-gnu/librt.so
For compatibility with CMake 3.11 and below this check is ignoring it.
Call Stack (most recent call first):
src/libbson/CMakeLists.txt:91 (CHECK_INCLUDE_FILE)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Looking for strings.h - found
-- Looking for strlcpy
-- Looking for strlcpy - not found
-- Looking for clock_gettime
-- Looking for clock_gettime - found
-- Looking for strnlen
-- Looking for strnlen - found
-- Looking for stdbool.h
-- Looking for stdbool.h - found
-- Looking for SYS_gettid
-- Looking for SYS_gettid - found
-- Looking for syscall
-- Looking for syscall - found
-- Performing Test HAVE_ATOMIC_32_ADD_AND_FETCH
-- Performing Test HAVE_ATOMIC_32_ADD_AND_FETCH - Success
-- Performing Test HAVE_ATOMIC_64_ADD_AND_FETCH
-- Performing Test HAVE_ATOMIC_64_ADD_AND_FETCH - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- 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.17.3
-- 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'
-- Found libzstd, version 1.3.3
-- Found zstd version 1.3.3 in
-- 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
-- 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: SRC_PATH/mongo-c-driver-1.17.3/cmake-build
I was building with this command:
$ cmake --build .
Everything works perfectly fine. So far, I haven’t found a test or example that’s not working.
When I try this it also works fine (adjusted paths):
$ gcc -o hello_mongoc hello_mongoc.c -I./include -L. -lmongoc-1.0 -lbson-1.0 -Wl,-rpath .
This command however gives the errors mentioned above:
$ gcc -o hello_mongo hello_mongoc.c -I./include -L. -lmongoc-static-1.0 -lbson-static-1.0 -pthread -lrt -lresolv -lcrypto -lssl -lz -lsasl2 -lzstd
./libmongoc-static-1.0.a(mongoc-scram.c.o): In function `_mongoc_sasl_prep_impl':
mongoc-scram.c:(.text+0x61b): undefined reference to `u_strFromUTF8_60'
mongoc-scram.c:(.text+0x667): undefined reference to `u_strFromUTF8_60'
mongoc-scram.c:(.text+0x682): undefined reference to `usprep_openByType_60'
mongoc-scram.c:(.text+0x6ad): undefined reference to `usprep_prepare_60'
mongoc-scram.c:(.text+0x6fa): undefined reference to `usprep_prepare_60'
mongoc-scram.c:(.text+0x718): undefined reference to `usprep_close_60'
mongoc-scram.c:(.text+0x72f): undefined reference to `u_strToUTF8_60'
mongoc-scram.c:(.text+0x76e): undefined reference to `u_strToUTF8_60'
mongoc-scram.c:(.text+0x80c): undefined reference to `usprep_close_60'
mongoc-scram.c:(.text+0x871): undefined reference to `usprep_close_60'
collect2: error: ld returned 1 exit status
For a moment I thought I was wrong to assume that gcc will automatically recognize that I try to link against static libraries. So I’ve tried to add the linker option “-Wl,-Bstatic” (I thought this is only required when static and shared libraries are available with the same basename and -l option would be ambiguous) but that always results in another linker error I can not explain.
$ g++ -o hello_mongoc hello_mongoc.c -I./include -L. -Wl,-Bstatic -lmongoc-static-1.0 -lbson-static-1.0
/usr/bin/ld: cannot find -lgcc_s
./libmongoc-static-1.0.a(mongoc-client.c.o): In function `mongoc_client_connect_tcp':
mongoc-client.c:(.text+0x1145): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
I’m not sure if this is even the right approach. Anyway, I’ve tried this:
$ gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ ln -s /usr/lib/gcc/x86_64-linux-gnu/7.5.0/libgcc_s.so libgcc_s.so
$ gcc -o hello_mongoc hello_mongoc.c -I./include -L. -l:./libgcc_s.so -Wl,-Bstatic -lmongoc-static-1.0 -lbson-static-1.0
/usr/bin/ld: cannot find -lgcc_s
./libmongoc-static-1.0.a(mongoc-client.c.o): In function `mongoc_client_connect_tcp':
mongoc-client.c:(.text+0x1145): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
However, the following command is working (it slightly differs from the call I posted previously because I was doing a clean start to prepare this info and installed some additional packages):
$ gcc -o hello_mongo hello_mongoc.c -I./include -L. -lmongoc-static-1.0 -lbson-static-1.0 -pthread -lrt -lresolv -lcrypto -lssl -lz -lsasl2 -lzstd -licuuc
Contact me if you need more specific details. I also want to let you know that I’m OK with it. I totally understand if you want to look into this and I’ll try to provide you with any further information you need. Just please don’t do it for my sake.
edit: FYI I just build the C driver but I don’t install it