I'm trying to compile a simple .cpp using the mongocxx lib. This is my code string_tests.cpp:
#include <iostream>
#include <mongocxx/instance.hpp>
using namespace std;
using namespace mongocxx;
int main() {
instance instance{}; // This should be done only once.
cout << "hello" << endl;
return 0;
}
I already have built the mongocxx library, I have everyting on C:\MinGW\thirdParty, this is the structure:
- C:\MinGW\thirdParty\mongo-c-driver\bin
- C:\MinGW\thirdParty\mongo-c-driver\lib
- C:\MinGW\thirdParty\mongo-c-driver\include
- C:\MinGW\thirdParty\mongo-cxx-driver\bin
- C:\MinGW\thirdParty\mongo-cxx-driver\lib
- C:\MinGW\thirdParty\mongo-cxx-driver\include (<-- here are the \bsoncxx\v_noabi and \mongocxx\v_noabi folders)
And I also added the bin folders to my PATH environment variable
The Mongo documentation said that I can compile my file with the next:
g++ --std=c++17 L:\dev\cpp\tests\string_tests.cpp -o L:\dev\cpp\tests\string_tests.exe -IC:\MinGW\thirdParty\mongo-cxx-driver\include\mongocxx\v_noabi -IC:\MinGW\thirdParty\mongo-cxx-driver\include\bsoncxx\v_noabi -LC:\MinGW\thirdParty\mongo-cxx-driver\lib -lmongocxx -lbsoncxx
I tried to compile my .cpp, it give me the next error:
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\MyUser\AppData\Local\Temp\ccmX2SEM.o:string_tests.c:(.text+0x4c): undefined reference to `__imp__ZN8mongocxx7v_noabi8instanceC1Ev'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\MyUser\AppData\Local\Temp\ccmX2SEM.o:string_tests.c:(.text+0x8c): undefined reference to `__imp__ZN8mongocxx7v_noabi8instanceD1Ev'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\MyUser\AppData\Local\Temp\ccmX2SEM.o:string_tests.c:(.text+0xc9): undefined reference to `__imp__ZN8mongocxx7v_noabi8instanceD1Ev'
collect2.exe: error: ld returned 1 exit status
I also tried it adding the bson libraries and included paths and I'm getting the same problem:
g++ --std=c++17 L:\dev\cpp\tests\string_tests.cpp -o L:\dev\cpp\tests\string_tests.exe -IC:\MinGW\thirdParty\mongo-cxx-driver\include\mongocxx\v_noabi -IC:\MinGW\thirdParty\mongo-cxx-driver\include\bsoncxx\v_noabi -IC:\MinGW\thirdParty\mongo-c-driver\include\libbson-1.0 -IC:\MinGW\thirdParty\mongo-c-driver\include\libmongoc-1.0 -LC:\MinGW\thirdParty\mongo-cxx-driver\lib -lmongocxx -lbsoncxx -LC:\MinGW\thirdParty\mongo-c-driver\lib -lbson-1.0 -lmongoc-1.0
I used this mongocxx driver installation in another project and it's working perfectly (I'm using it in a Unreal Engine CPP project which have a very different compilation settings, and it's working there, I just want to simplify the process compiling it in a simple .cpp file for fast tests).
Can anyone tell me what am I doing worng? Thanks in advance