Just tried the following code similar to mongocxx C++ API Sample
#include <iostream>
#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/stdx.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/builder/basic/document.hpp>
int main()
{
using namespace std;
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_array;
using bsoncxx::builder::basic::make_document;
mongocxx::instance instance{}; // This should be done only once.
mongocxx::uri uri("mongodb://localhost:27017");
mongocxx::client client(uri);
auto db {client["test"]};
auto collection {db["books"]};
return 0;
}
and I added the following three statements to CMakeLists.txt
target_include_directories(${PROJECT_NAME} PUBLIC
/usr/include/
/usr/local/include
/usr/local/include/mongocxx/v_noabi
/usr/local/include/bsoncxx/v_noabi
/usr/local/include/libbson-1.0
)
target_link_directories(${PROJECT_NAME} PUBLIC
/usr/lib/x86_64-linux-gnu/
/usr/local/lib/
)
target_link_libraries(${PROJECT_NAME}
libmongocxx.so
libbsoncxx.so
libmongoc-1.0.so
libsasl2.so
libicuuc.so
libssl.so
)
I tried building the project, but all I got was this:
/usr/bin/ld: warning: libicuuc.so.66, needed by /usr/local/lib/libmongoc-1.0.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /usr/local/lib/libmongoc-1.0.so: undefined reference to `u_strFromUTF8_66'
/usr/bin/ld: /usr/local/lib/libmongoc-1.0.so: undefined reference to `usprep_close_66'
/usr/bin/ld: /usr/local/lib/libmongoc-1.0.so: undefined reference to `u_strToUTF8_66'
/usr/bin/ld: /usr/local/lib/libmongoc-1.0.so: undefined reference to `usprep_prepare_66'
/usr/bin/ld: /usr/local/lib/libmongoc-1.0.so: undefined reference to `usprep_openByType_66'
collect2: error: ld returned 1 exit status
I can compile and add libicuu myself, but I don't know what libraries I should add to get rid of the undefined references (u_strFromUTF8_66, usprep_close_66, u_strToUTF8_66, usprep_prepare_66, usprep_openByType_66).
What library defines u_strFromUTF8_66, usprep_close_66, u_strToUTF8_66, usprep_prepare_66, usprep_openByType_66?
P.S. My OS is Ubuntu 22.04.
I tried running the code in Qt Creator.