Mongo cxx driver issue - undefined reference to `__imp__ZN7bsoncxx7v_

When I’m trying to compile the following code I’m getting so many issues. But mongoc and mongocxx drivers are installed on my pc.

code :

#include <cstdint>
#include <iostream>
#include <vector>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/instance.hpp>
#include <bsoncxx/builder/stream/helpers.hpp>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/builder/stream/array.hpp>

using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::finalize;
using bsoncxx::builder::stream::open_array;
using bsoncxx::builder::stream::open_document;

int main()
{
    mongocxx::instance instance{}; // This should be done only once.
    mongocxx::uri uri("mongodb://localhost:27017");
    mongocxx::client client(uri);

    mongocxx::database db = client["sliit"];
    return 0;
}

compiling command :
g++ --std=c++17 main.cpp -o test -IC:/mongo-cxx-driver/include/mongocxx/v_noabi -IC:/mongo-cxx-driver/include/bsoncxx/v_noabi -LC:/mongo-cxx-driver /lib -lmongocxx -lbsoncxx -IC:\local\boost_1_60_0

Error :

c:/users/tharindu/downloads/programs/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Tharindu\AppData\Local\Temp\ccRL6mIk.o:main.cpp:(
.text+0x2d): undefined reference to `__imp__ZN8mongocxx7v_noabi8instanceC1Ev'
c:/users/tharindu/downloads/programs/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Tharindu\AppData\Local\Temp\ccRL6mIk.o:main.cpp:(
.text+0x36): undefined reference to `__imp__ZN8mongocxx7v_noabi3uri13k_default_uriB5cxx11E'
c:/users/tharindu/downloads/programs/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Tharindu\AppData\Local\Temp\ccRL6mIk.o:main.cpp:(
.text+0x54): undefined reference to `__imp__ZN8mongocxx7v_noabi3uriC1EN7bsoncxx7v_noabi6string13view_or_valueE'
c:/users/tharindu/downloads/programs/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Tharindu\AppData\Local\Temp\ccRL6mIk.o:main.cpp:(
.text+0x94): undefined reference to `__imp__ZN8mongocxx7v_noabi6clientC1ERKNS0_3uriERKNS0_7options6clientE'
c:/users/tharindu/downloads/programs/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Tharindu\AppData\Local\Temp\ccRL6mIk.o:main.cpp:(
.text+0xb0): undefined reference to `__imp__ZN8mongocxx7v_noabi3uriD1Ev'
c:/users/tharindu/downloads/programs/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Tharindu\AppData\Local\Temp\ccRL6mIk.o:main.cpp:(
.text+0xe4): undefined reference to `__imp__ZN8mongocxx7v_noabi6clientD1Ev'
c:/users/tharindu/downloads/programs/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Tharindu\AppData\Local\Temp\ccRL6mIk.o:main.cpp:(
.text+0xf4): undefined reference to `__imp__ZN8mongocxx7v_noabi8instanceD1Ev'
c:/users/tharindu/downloads/programs/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Tharindu\AppData\Local\Temp\ccRL6mIk.o:main.cpp:(
.text+0x11a): undefined reference to `__imp__ZN8mongocxx7v_noabi3uriD1Ev'
c:/users/tharindu/downloads/programs/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Tharindu\AppData\Local\Temp\ccRL6mIk.o:main.cpp:(
.text+0x140): undefined reference to `__imp__ZN8mongocxx7v_noabi6clientD1Ev'
c:/users/tharindu/downloads/programs/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Tharindu\AppData\Local\Temp\ccRL6mIk.o:main.cpp:(
.text+0x155): undefined reference to `__imp__ZN8mongocxx7v_noabi8instanceD1Ev'
c:/users/tharindu/downloads/programs/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Tharindu\AppData\Local\Temp\ccRL6mIk.o:main.cpp:(
.text$_ZN7bsoncxx7v_noabi7builder6stream8documentC1Ev[_ZN7bsoncxx7v_noabi7builder6stream8documentC1Ev]+0x33): undefined reference to `__imp__ZN7bsoncxx7v_noabi7builder4coreC1Eb'
c:/users/tharindu/downloads/programs/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Tharindu\AppData\Local\Temp\ccRL6mIk.o:main.cpp:(
.text$_ZN7bsoncxx7v_noabi7builder6stream8documentD1Ev[_ZN7bsoncxx7v_noabi7builder6stream8documentD1Ev]+0x1a): undefined reference to `__imp__ZN7bsoncxx7v_noabi7builder4coreD1Ev'

Can someone please help me regarding this issue?

It looks like you’re following the tutorial here: Tutorial for mongocxx

-LC:/mongo-cxx-driver /lib

I think you have an extraneous space before /lib. Also, I don’t see any use of boost in your code, so you might want to remove that include directive.

@Bernie_Hackett I think that happens that I’ve used different type of compilers for mongocxx install and project build . I used the same compiler for both and then I get rid of above issue . But I am still getting a error , can you please help me on fixing this issue

main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall bsoncxx::v_noabi::string::view_or_value::view_or_value(char const *)" (__imp_??0view_or_value@string@v_noabi@bsoncxx@@QAE@PBD@Z) referenced in function _main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall mongocxx::v_noabi::options::client::client(void)" (__imp_??0client@options@v_noabi@mongocxx@@QAE@XZ) referenced in function _main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall mongocxx::v_noabi::options::client::~client(void)" (__imp_??1client@options@v_noabi@mongocxx@@QAE@XZ) referenced in function _main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall mongocxx::v_noabi::uri::uri(class bsoncxx::v_noabi::string::view_or_value)" (__imp_??0uri@v_noabi@mongocxx@@QAE@Vview_or_value@string@1bsoncxx@@@Z) referenced in function _main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall mongocxx::v_noabi::uri::~uri(void)" (__imp_??1uri@v_noabi@mongocxx@@QAE@XZ) referenced in function _main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall mongocxx::v_noabi::client::client(class mongocxx::v_noabi::uri const &,class mongocxx::v_noabi::options::client const &)" (__imp_??0client@v_noabi@mongocxx@@QAE@ABVuri@12@ABV0options@12@@Z) referenced in function _main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall mongocxx::v_noabi::client::~client(void)" (__imp_??1client@v_noabi@mongocxx@@QAE@XZ) referenced in function _main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall mongocxx::v_noabi::instance::instance(void)" (__imp_??0instance@v_noabi@mongocxx@@QAE@XZ) referenced in function _main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall mongocxx::v_noabi::instance::~instance(void)" (__imp_??1instance@v_noabi@mongocxx@@QAE@XZ) referenced in function _main
untitled5.exe : fatal error LNK1120: 9 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files\JetBrains\CLion 2020.3.3\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.

:frowning: :frowning: help ???

Hi @Tharindu_Balasooriya,

It looks like you resolved your issue from your post on stack overflow here. Please let me know if you’re still running into any problems.

@Clyde_Bazile_III
Yes I got it resolved, Thankyou very much

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.