1

I'm trying to execute the following code but I'm ending up getting issues I am getting an error called error LNK2019: unresolved external symbol and NMAKE: fatal error U1077: I don't have any idea of fixing this Can someone please help me to fix this? my msvc version is 19.28.29913 and mongocxx version is 3.6.2

code :

#include <iostream>
#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>

int main() {
    std::cout << "Hello, World!" << std::endl;
    mongocxx::instance instance{}; // This should be done only once.
    mongocxx::uri uri("mongodb://localhost:27017");
    mongocxx::client client(uri);
    return 0;
}

Error :

"C:\Program Files\JetBrains\CLion 2020.3.3\bin\cmake\win\bin\cmake.exe" --build C:\Users\Tharindu\CLionProjects\untitled\cmake-build-debug --target untitled
[ 50%] Linking CXX executable untitled.exe
LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1428~1.299\bin\Hostx86\x86\link.exe /nologo @CMakeFiles\untitled.dir\objects1.rsp /out:untitled.exe /implib:untitled.lib /pdb:C:\Users\Tharindu\CLionProjects\untitled\cmake-build-debug\untitled.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\untitled.dir/intermediate.manifest CMakeFiles\untitled.dir/manifest.res" failed (exit code 1120) with the following output:
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
untitled.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.

  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – 273K Mar 22 '21 at 04:29
  • NO I don't see a way to resolve my issue :( – Tharindu Balasuriya Mar 22 '21 at 04:40
  • If you use CMake for build your project, then exactly `CMakeLists.txt` script is responsible for linking with the libraries. Show that script (add it to the question post). – Tsyvarev Mar 22 '21 at 08:12
  • Yes issue was on the CMake List, i fixed it as follow,now its working, Thankyou verymuch – Tharindu Balasuriya Mar 22 '21 at 09:52
  • `cmake_minimum_required(VERSION 3.17) project(untitled4) find_package(libmongocxx REQUIRED) find_package(libbsoncxx REQUIRED) include_directories(${LIBMONGOCXX_INCLUDE_DIR}) include_directories(${LIBBSONCXX_INCLUDE_DIR}) include_directories("C:/mongo-cxx-driver/include/mongocxx/v_noabi") include_directories("C:/mongo-cxx-driver/include/bsoncxx/v_noabi") include_directories("C:/local/boost_1_75_0") set(CMAKE_CXX_STANDARD 17) add_executable(untitled4 main.cpp) target_link_libraries(untitled4 ${LIBMONGOCXX_LIBRARIES}) target_link_libraries(untitled4 ${LIBBSONCXX_LIBRARIES}) ` – Tharindu Balasuriya Mar 22 '21 at 09:52
  • 1
    I've edited the question with the CMake List, for anyone getting the same issue – Tharindu Balasuriya Mar 22 '21 at 09:53

0 Answers0