Undefined reference to bsoncxx when try to compile

os: Windows 10
compiler: MinGW w64 8.1.0 i686
mongo-c-driver: 1.16.2
mongo-cxx-driver: commit 4629521 of branch releases/v3.5

Compiled with the options:

BSONCXX_POLY_USE_STD=ON
CMAKE_CXX_STANDARD=17

I receive the following errors when try to compile mongo-cxx-driver:

[ 13%] Linking CXX executable test_bson.exe
CMakeFiles\test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0xf17): undefined reference to `_imp___ZN7bsoncxx7v_noabi5types10b_document7type_idE'
CMakeFiles\test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x10ae): undefined reference to `_imp___ZN7bsoncxx7v_noabi5types7b_int327type_idE'
CMakeFiles\test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x1563): undefined reference to `_imp___ZN7bsoncxx7v_noabi5types7b_array7type_idE'
CMakeFiles\test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x16f2): undefined reference to `_imp___ZN7bsoncxx7v_noabi5types7b_int327type_idE'
CMakeFiles\test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x1b5d): undefined reference to `_imp___ZN7bsoncxx7v_noabi5types7b_int327type_idE'
CMakeFiles\test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x1e42): undefined reference to `_imp___ZN7bsoncxx7v_noabi5types6b_bool7type_idE'
CMakeFiles\test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x2292): undefined reference to `_imp___ZN7bsoncxx7v_noabi5types7b_int327type_idE'
CMakeFiles\test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x2579): undefined reference to `_imp___ZN7bsoncxx7v_noabi5types6b_bool7type_idE'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [src\bsoncxx\test\CMakeFiles\test_bson.dir\build.make:236: src/bsoncxx/test/test_bson.exe] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:987: src/bsoncxx/test/CMakeFiles/test_bson.dir/all] Error 2
mingw32-make: *** [Makefile:160: all] Error 2

@AlexxanderX what are the complete command lines you used to compiler the C driver and the C++ driver?

For C driver I used:

cd MY_PROJECT/extlibs
curl -LO https://github.com/mongodb/mongo-c-driver/archive/1.16.2.zip
7z x 1.16.2.zip -r
cd mongo-c-driver-1.16.2/build
cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_VERSION=1.16.2 -DCMAKE_INSTALL_PREFIX=MY_PROJECT/extlibs/mongo-c-driver-1.16.2 ..
mingw32-make install

Here is the log of cmake and make: https://pastebin.com/2ZeYiY3F

And for the mongo-cxx-driver:

cd MY_PROJECT/extlibs
curl -LO https://github.com/mongodb/mongo-cxx-driver/archive/r3.5.0.zip
7z x r3.5.0.zip -r
cd mongo-cxx-driver-r3.5.0/build
cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_VERSION=3.5.0 -DCMAKE_INSTALL_PREFIX=MY_PROJECT/extlibs/mongo-cxx-driver-r3.5.0 -DBSONCXX_POLY_USE_STD=ON -DCMAKE_CXX_STANDARD=17 -DCMAKE_PREFIX_PATH=MY_PROJECT/extlibs/mongo-c-driver-1.16.2 ..
mingw32-make

Here is the output of cmake and make: https://pastebin.com/CQpKYr0f

Thank you for looking into this.

@AlexxanderX our test matrix for the C++ Driver only includes Visual Studio for Windows builds. I was not able to build with MinGW either. Since GCC works on other platforms, I am not sure why MinGW would not work on Windows, but it looks you will need to use Visual Studio. Note that you will want to build both the C driver and C++ driver with the same tool chain. Building the C driver with MinGW and the C++ driver with Visual Studio is likely to result in problems.

1 Like