[CXX-2001] Undefined reference to bsoncxx when compiling test_bson with MinGW Created: 17/Apr/20  Updated: 17/Jan/23

Status: Backlog
Project: C++ Driver
Component/s: Build
Affects Version/s: 3.5.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Alexandru Prisacariu Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

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


Issue Links:
Related
is related to CXX-1779 Mongocxx driver build on windows with... Backlog
Epic Link: CXX-2634

 Description   

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



 Comments   
Comment by Kevin Albertson [ 29/Aug/20 ]

Hi zalexxanderx@gmail.com,

Thank you for the report. I was able to reproduce this locally using MinGW and MSYS:

cmake -DCMAKE_PREFIX_PATH="/c/mongo-c-driver-1.17.0-pre" -DCMAKE_CXX_COMPILER="g++" -DBUILD_VERSION=3.5.0 -DCMAKE_CXX_STANDARD=17 -DCMAKE_C_COMPILER=gcc -G "MSYS Makefiles" ..
cmake --build . --target test_bson

Produces the error:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x107c): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types10b_document7type_idE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x1269): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types7b_int327type_idE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x18fb): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types7b_array7type_idE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x1ad6): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types7b_int327type_idE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x20ec): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types7b_int327type_idE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x246c): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types6b_bool7type_idE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x4a44): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types7b_int327type_idE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x4dc4): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types6b_bool7type_idE'
collect2.exe: error: ld returned 1 exit status
make[3]: *** [src/bsoncxx/test/CMakeFiles/test_bson.dir/build.make:222: src/bsoncxx/test/test_bson.exe] Error 1
make[2]: *** [CMakeFiles/Makefile2:587: src/bsoncxx/test/CMakeFiles/test_bson.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:599: src/bsoncxx/test/CMakeFiles/test_bson.dir/rule] Error 2
make: *** [Makefile:357: test_bson] Error 2

Note, however, this only appears in the test target. I am still able to build mongocxx_shared/bsoncxx_shared targets. If you only need to build the libraries, consider only building those targets.

Generated at Wed Feb 07 22:04:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.