Error building libmongoc on swift:5.5.3-bionic

Hi,

I've been using swift + mongo on unbuntu with the official swift docker images for a while now successfully.
Trying to upgrade to 5.5 I'm getting an error compiling libmongoc.

This is the Dockerfile with the libmongoc part following instructions here:

(The exact same Dockerfile but with swift:5.4-bionic works just fine)

FROM swift:5.5.3-bionic

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends apt-utils

# Install libmongoc

RUN apt-get install -y cmake libssl-dev libsasl2-dev
RUN apt-get install -y wget

RUN wget https://github.com/mongodb/mongo-c-driver/releases/download/1.21.2/mongo-c-driver-1.21.2.tar.gz
RUN tar xzf mongo-c-driver-1.21.2.tar.gz
RUN cd mongo-c-driver-1.21.2 && \
    mkdir cmake-build && \
    cd cmake-build && \
    cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF .. && \
    cmake --build .

This failed during the cmake with:

#10 31.59 [ 37%] Linking C shared library libmongoc-1.0.so
#10 31.73 [ 37%] Built target mongoc_shared
#10 31.76 Scanning dependencies of target common-operations
#10 31.77 [ 37%] Building C object src/libmongoc/CMakeFiles/common-operations.dir/examples/common_operations/common-operations.c.o
#10 31.90 [ 37%] Linking C executable common-operations
#10 31.96 libmongoc-1.0.so.0.0.0: undefined reference to usprep_prepare_65_swift' #10 31.96 libmongoc-1.0.so.0.0.0: undefined reference to u_strFromUTF8_65_swift'
#10 31.96 libmongoc-1.0.so.0.0.0: undefined reference to usprep_openByType_65_swift' #10 31.96 libmongoc-1.0.so.0.0.0: undefined reference to u_strToUTF8_65_swift'
#10 31.96 libmongoc-1.0.so.0.0.0: undefined reference to `usprep_close_65_swift'
#10 31.96 collect2: error: ld returned 1 exit status
#10 31.96 make[2]: *** [src/libmongoc/common-operations] Error 1
#10 31.96 src/libmongoc/CMakeFiles/common-operations.dir/build.make:101: recipe for target 'src/libmongoc/common-operations' failed
#10 31.96 CMakeFiles/Makefile2:1715: recipe for target 'src/libmongoc/CMakeFiles/common-operations.dir/all' failed
#10 31.96 make[1]: *** [src/libmongoc/CMakeFiles/common-operations.dir/all] Error 2
#10 31.96 Makefile:162: recipe for target 'all' failed
#10 31.96 make: *** [all] Error 2

Any help much appreciated.
Thanks,
Mike.

CC @kmahar

1 Like

The Swift driver actually vendors libmongoc, so it gets built along with the driver during the Swift build process and you don't have to install it yourself. You do need to install libmongoc's system dependencies though. On Ubuntu, that's just this portion of your install script:

RUN apt-get install libssl-dev libsasl2-dev
2 Likes