I installed Mongo C++ Driver using following shell script,
#!/bin/bash
echo "Building MongoDB Core Dependency"
cd /home &&
wget https://github.com/mongodb/mongo-c-driver/releases/download/1.17.0/mongo-c-driver-1.17.0.tar.gz &&
tar xzf mongo-c-driver-1.17.0.tar.gz &&
cd mongo-c-driver-1.17.0 &&
mkdir cmake-build &&
cd cmake-build &&
cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DCMAKE_BUILD_TYPE=Release .. &&
echo "Installing MongoDB Core Dependency" &&
sudo make install &&
cd /home &&
echo "Downloading MongoDB Driver" &&
git clone https://github.com/mongodb/mongo-cxx-driver.git --branch releases/stable --depth 1 &&
cd mongo-cxx-driver/build &&
echo "Building and Installing MongoDB Driver" &&
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_AND_STATIC_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr/local &&
make && sudo make install
I compile my app like this (w/ Static Linking),
g++ main.cpp -std=c++11 -ltins -DMONGOCXX_STATIC /
-DBSONCXX_STATIC -DMONGOC_STATIC /
-DBSON_STATIC - I/usr/local/include/libmongoc-1.0 /
-I/usr/local/include/libbson-1.0 -I/usr/local/include/mongocxx/v_noabi /
-I/usr/local/include/bsoncxx/v_noabi -L/usr/local/lib -lmongocxx-static /
-lbsoncxx-static -lmongoc-static-1.0 -lz -lsasl2 -lssl -lcrypto -lrt /
-lresolv -pthread -lbson-static-1.0 /
-lm /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libm.so /
-pthread -o app
However, The compile process fails with,
/usr/bin/ld: /usr/local/lib/libmongoc-static-1.0.a(mongoc-scram.c.o): in function `_mongoc_sasl_prep_impl':
mongoc-scram.c:(.text+0x61e): undefined reference to `u_strFromUTF8_66'
/usr/bin/ld: mongoc-scram.c:(.text+0x66a): undefined reference to `u_strFromUTF8_66'
/usr/bin/ld: mongoc-scram.c:(.text+0x685): undefined reference to `usprep_openByType_66'
/usr/bin/ld: mongoc-scram.c:(.text+0x6b0): undefined reference to `usprep_prepare_66'
/usr/bin/ld: mongoc-scram.c:(.text+0x702): undefined reference to `usprep_prepare_66'
/usr/bin/ld: mongoc-scram.c:(.text+0x720): undefined reference to `usprep_close_66'
/usr/bin/ld: mongoc-scram.c:(.text+0x739): undefined reference to `u_strToUTF8_66'
/usr/bin/ld: mongoc-scram.c:(.text+0x77a): undefined reference to `u_strToUTF8_66'
/usr/bin/ld: mongoc-scram.c:(.text+0x814): undefined reference to `usprep_close_66'
/usr/bin/ld: mongoc-scram.c:(.text+0x871): undefined reference to `usprep_close_66'
collect2: error: ld returned 1 exit status
make: *** [Makefile:3: all] Error 1
It was worked before on my other machine and not sure why it doesn't work right now.
I even reinstalled Ubuntu and that didn't work out too.
My Ubuntu version is 20.04
and G++ version is 9.3.0
Aucun commentaire:
Enregistrer un commentaire