Fatal error building C++ drivers with VS 2022 under Win10 - are errors OK?

I’m getting a fatal error and warnings during compile. Data security is going to be of v. high importance so even if I just ignored it and a linked-in app worked I’m not sure whether it would be safe?

I’m compiling the c++ drivers under Win10 with VS2022 (having just built and installed the c drivers)
However getting a fatal error from bson_builder.cpp (as per output below)
and a warning for many other files
“C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc”
as below
I did try and add EHsc to the flags in CMakeLists.txt, but it seem to be ignored
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g --coverage /EHsc")

These are the commands entered via VS Command Prompt:
>> cmake .. -G "Visual Studio 17 2022" -A x64 -DBUILD_VERSION=3.6.0 -DBOOST_ROOT=C:\Users\dgm55\source\repos\boost_1_81_0 -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_FLAGS="/Zc:__cplusplus" -DCMAKE_PREFIX_PATH=C:\Users\dgm55\source\repos\mongo-c-driver -DCMAKE_INSTALL_PREFIX=C:\Users\dgm55\source\repos\mongo-cxx-driver
>> cmake --build .

This is the one of the warnings and the fatal

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\ostream(305,1): warning C4530
: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc [C:\Users\dgm55\source\repos\mongo-cx
x-driver\build\src\bsoncxx\test\test_bson.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\ostream(298,1): message : whi
le compiling class template member function 'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,s
td::char_traits<char>>::operator <<(unsigned int)' [C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\test
\test_bson.vcxproj]
C:\Users\dgm55\source\repos\mongo-cxx-driver\src\bsoncxx/test_util/to_string.hh(53,57): message : see reference to func
tion template instantiation 'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<
char>>::operator <<(unsigned int)' being compiled [C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\test\
test_bson.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\ostream(671,75): message : se
e reference to class template instantiation 'std::basic_ostream<char,std::char_traits<char>>' being compiled [C:\Users\
dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\test\test_bson.vcxproj]
  Generating Code...
C:\Users\dgm55\source\repos\mongo-cxx-driver\src\bsoncxx\test\bson_builder.cpp(1705): fatal  error C1001: Internal comp
iler error. [C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\test\test_bson.vcxproj]
  (compiler file 'D:\a\_work\1\s\src\vctools\Compiler\Utc\src\p2\main.c', line 224)
   To work around this problem, try simplifying or changing the program near the locations listed above.

The full output is below

C:\Users\dgm55\source\repos\mongo-cxx-driver\build>cmake .. -G "Visual Studio 17 2022" -A x64  -DBUILD_VERSION=3.6.0  -DBOOST_ROOT=C:\Users\dgm55\source\repos\boost_1_81_0  -DCMAKE_CXX_STANDARD=17  -DCMAKE_CXX_FLAGS="/Zc:__cplusplus"  -DCMAKE_PREFIX_PATH=C:\Users\dgm55\source\repos\mongo-c-driver  -DCMAKE_INSTALL_PREFIX=C:\Users\dgm55\source\repos\mongo-cxx-driver
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19043.
-- No build type selected, default is Release
-- Auto-configuring bsoncxx to use C++17 std library polyfills since C++17 is active and user didn't specify otherwise
bsoncxx version: 3.6.0
found libbson version 3.6.0
mongocxx version: 3.6.0
found libmongoc version 3.6.0
-- Build files generated for:
--      build system: Visual Studio 17 2022
--      instance: C:/Program Files/Microsoft Visual Studio/2022/Community
--      instance: x64
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/dgm55/source/repos/mongo-cxx-driver/build

C:\Users\dgm55\source\repos\mongo-cxx-driver\build>cmake --build .
MSBuild version 17.4.1+9a89d02ff for .NET Framework
  bsoncxx_shared.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\Debug\bsoncxx.dll
  bsoncxx_testing.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\Debug\bsoncxx-testing.dll
  mongocxx_mocked.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\Debug\mongocxx-mocked.dll
  mongocxx_shared.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\Debug\mongocxx.dll
  array.cpp
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\ostream(305,1): warning C4530
: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc [C:\Users\dgm55\source\repos\mongo-cx
x-driver\build\src\bsoncxx\test\test_bson.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\ostream(298,1): message : whi
le compiling class template member function 'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,s
td::char_traits<char>>::operator <<(unsigned int)' [C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\test
\test_bson.vcxproj]
C:\Users\dgm55\source\repos\mongo-cxx-driver\src\bsoncxx/test_util/to_string.hh(53,57): message : see reference to func
tion template instantiation 'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<
char>>::operator <<(unsigned int)' being compiled [C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\test\
test_bson.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\ostream(671,75): message : se
e reference to class template instantiation 'std::basic_ostream<char,std::char_traits<char>>' being compiled [C:\Users\
dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\test\test_bson.vcxproj]
  bson_b_date.cpp
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\ostream(305,1): warning C4530
: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc [C:\Users\dgm55\source\repos\mongo-cx
x-driver\build\src\bsoncxx\test\test_bson.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\ostream(298,1): message : whi
le compiling class template member function 'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,s
td::char_traits<char>>::operator <<(unsigned int)' [C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\test
\test_bson.vcxproj]
C:\Users\dgm55\source\repos\mongo-cxx-driver\src\bsoncxx/test_util/to_string.hh(53,57): message : see reference to func
tion template instantiation 'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<
char>>::operator <<(unsigned int)' being compiled [C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\test\
test_bson.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\ostream(671,75): message : se
e reference to class template instantiation 'std::basic_ostream<char,std::char_traits<char>>' being compiled [C:\Users\
dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\test\test_bson.vcxproj]
  main.cpp
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\ostream(544,1): warning C4530
: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc [C:\Users\dgm55\source\repos\mongo-cx
x-driver\build\src\bsoncxx\test\test_bson.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\ostream(536,1): message : whi
le compiling class template member function 'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,s
td::char_traits<char>>::write(const _Elem *,std::streamsize)' [C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\b
soncxx\test\test_bson.vcxproj]
          with
          [
              _Elem=char
          ]
C:\Users\dgm55\source\repos\mongo-cxx-driver\src\third_party\catch\include\catch.hpp(13929,9): message : see reference
to function template instantiation 'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_
traits<char>>::write(const _Elem *,std::streamsize)' being compiled [C:\Users\dgm55\source\repos\mongo-cxx-driver\build
\src\bsoncxx\test\test_bson.vcxproj]
          with
          [
              _Elem=char
          ]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\ostream(671,75): message : se
e reference to class template instantiation 'std::basic_ostream<char,std::char_traits<char>>' being compiled [C:\Users\
dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\test\test_bson.vcxproj]
  Generating Code...
test_bson.dir\Debug\bson_builder.obj : fatal error LNK1136: invalid or corrupt file [C:\Users\dgm55\source\repos\mongo-
cxx-driver\build\src\bsoncxx\test\test_bson.vcxproj]
  test_client_side_encryption_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Deb
  ug\test_client_side_encryption_specs.exe
  test_command_monitoring_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\t
  est_command_monitoring_specs.exe
  test_crud_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_crud_specs
  .exe
  test_driver.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_driver.exe
  test_gridfs_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_gridfs_s
  pecs.exe
  test_instance.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_instance.exe
  test_logging.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_logging.exe
  test_mongohouse_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_mong
  ohouse_specs.exe
  test_read_write_concern_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\t
  est_read_write_concern_specs.exe
  test_retryable_reads_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test
  _retryable_reads_specs.exe
  test_transactions_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_tr
  ansactions_specs.exe
  test_unified_format_spec.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_u
  nified_format_spec.exe
  test_versioned_api.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_version
  ed_api.exe

C:\Users\dgm55\source\repos\mongo-cxx-driver\build>cmake --build . --target install
MSBuild version 17.4.1+9a89d02ff for .NET Framework
  bsoncxx_shared.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\Debug\bsoncxx.dll
  bsoncxx_testing.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\bsoncxx\Debug\bsoncxx-testing.dll
  mongocxx_mocked.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\Debug\mongocxx-mocked.dll
  mongocxx_shared.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\Debug\mongocxx.dll
test_bson.dir\Debug\bson_builder.obj : fatal error LNK1136: invalid or corrupt file [C:\Users\dgm55\source\repos\mongo-
cxx-driver\build\src\bsoncxx\test\test_bson.vcxproj]
  test_client_side_encryption_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Deb
  ug\test_client_side_encryption_specs.exe
  test_command_monitoring_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\t
  est_command_monitoring_specs.exe
  test_crud_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_crud_specs
  .exe
  test_driver.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_driver.exe
  test_gridfs_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_gridfs_s
  pecs.exe
  test_instance.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_instance.exe
  test_logging.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_logging.exe
  test_mongohouse_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_mong
  ohouse_specs.exe
  test_read_write_concern_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\t
  est_read_write_concern_specs.exe
  test_retryable_reads_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test
  _retryable_reads_specs.exe
  test_transactions_specs.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_tr
  ansactions_specs.exe
  test_unified_format_spec.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_u
  nified_format_spec.exe
  test_versioned_api.vcxproj -> C:\Users\dgm55\source\repos\mongo-cxx-driver\build\src\mongocxx\test\Debug\test_version
  ed_api.exe

C:\Users\dgm55\source\repos\mongo-cxx-driver\build>

Looking back I wonder if I might be missing dependencies even earlier in the toolchain.
I repeated the steps of recompiling the underlying C driver but even at the first step had missing stdlib headers (although not sure why cmake can’t find them as they’re definitly installed and the path seems to be comprehensive enough to cover them?)
Also despite a clean install of Strawberry Perl it still didn’t find the libzstd module which I presume is also related to the zlib error above that - although I can’t find any documentation on what needs to be installed there (it’s not listed as a dependency on the install page: Installing the MongoDB C Driver (libmongoc) and BSON library (libbson) — libmongoc 1.23.2)

Is there a precompiled package for windows I can use to just install the library/drivers? The only ones I have been able to track down are for Linux or Mac which I can’t use for this project.


C:\Users\dgm55\source\repos\mongo-c-driver\cmake-build>cmake .. -G "Visual Studio 17 2022" -A x64  -DBUILD_VERSION=3.6.0  -DBOOST_ROOT=C:\Users\dgm55\source\repos\boost_1_81_0  -DCMAKE_CXX_STANDARD=17  -DCMAKE_CXX_FLAGS="/Zc:__cplusplus"  -DCMAKE_PREFIX_PATH=C:\Users\dgm55\source\repos\mongo-c-driver  -DCMAKE_INSTALL_PREFIX=C:\Users\dgm55\source\repos\mongo-c-driver

-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19043.
-- The C compiler identification is MSVC 19.34.31937.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for a CXX compiler
-- Looking for a CXX compiler - C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe
-- The CXX compiler identification is MSVC 19.34.31937.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
storing BUILD_VERSION 3.6.0 in file VERSION_CURRENT for later use
-- Build and install static libraries
-- Found Python3: C:/Users/dgm55/AppData/Local/Programs/Python/Python311/python.exe (found version "3.11.2") found components: Interpreter
  -- Using bundled libbson
libbson version (from VERSION_CURRENT file): 3.6.0
-- Looking for snprintf
-- Looking for snprintf - found
-- Performing Test BSON_HAVE_TIMESPEC
-- Performing Test BSON_HAVE_TIMESPEC - Success
--     struct timespec found
-- Looking for gmtime_r
-- Looking for gmtime_r - not found
-- Looking for rand_r
-- Looking for rand_r - not found
-- Looking for strings.h
-- Looking for strings.h - not found
-- Looking for strlcpy
-- Looking for strlcpy - not found
-- Looking for stdbool.h
-- Looking for stdbool.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
libmongoc version (from VERSION_CURRENT file): 3.6.0
-- Searching for zlib CMake packages
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-- Enabling zlib compression (bundled)
-- Looking for include file unistd.h
-- Looking for include file unistd.h - not found
-- Looking for include file stdarg.h
-- Looking for include file stdarg.h - found
-- Searching for compression library zstd
-- Found PkgConfig: D:/StrawberryPerl/perl/bin/pkg-config.bat (found version "0.26")
-- Checking for module 'libzstd'
--   Can't find libzstd.pc in any of D:/StrawberryPerl/c/lib/pkgconfig
use the PKG_CONFIG_PATH environment variable, or
specify extra search paths via 'search_paths'
--   Not found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of socklen_t
-- Check size of socklen_t - done
-- Looking for sched_getcpu
-- Looking for sched_getcpu - not found
-- Searching for compression library header snappy-c.h
--   Not found (specify -DCMAKE_INCLUDE_PATH=/path/to/snappy/include for Snappy compression)
-- No ICU library found, SASLPrep disabled for SCRAM-SHA-256 authentication.
-- If ICU is installed in a non-standard directory, define ICU_ROOT as the ICU installation path.
Searching for libmongocrypt
-- libmongocrypt not found. Configuring without Client-Side Field Level Encryption support.
-- Performing Test MONGOC_HAVE_SS_FAMILY
-- Performing Test MONGOC_HAVE_SS_FAMILY - Failed
-- Compiling against Secure Channel
-- Compiling against Windows SSPI
-- Building with MONGODB-AWS auth support
-- Build files generated for:
--      build system: Visual Studio 17 2022
--      instance: C:/Program Files/Microsoft Visual Studio/2022/Community
--      instance: x64
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    BOOST_ROOT


-- Build files have been written to: C:/Users/dgm55/source/repos/mongo-c-driver/cmake-build

Hi @david_d ,

Can you try the steps outlined in Getting Started with MongoDB and C++ | MongoDB ?
C++ driver package is also available with vcpkg (vcpkg - Open source C/C++ dependency manager from Microsoft) however it may not have the latest version.

Thanks @Rishabh_Bisht!
I’ve installed with vcpkg - as at this point I just need to start with a basic test app
vcpkg install mongo-c-driver
vcpkg install mongo-cxx-driver
Newbie confession: If there had been a link to vcpkg in Windows I would have probably used that as the first option - but despite programming c++ for years I’ve never needed one in windows so missed the reference.

Assuming it works as we need I will try again following the steps in your article to ensure the latest build.

Getting closer…
I’ve had a look at your article but since this directs to the original links which (as above) I tried and failed to compile the c and c++ drivers I’m not going to get any further with compiling the drivers from scratch using that route.
Also obviously (although not to vcpkg nubes) the correct package manager command for a modern PC was not the ‘obvious’ command (as I listed above) (does anyone still develop for x86?!?) but:
vcpkg install mongo-c-driver:x64-windows
vcpkg install mongo-cxx-driverx64-windows

If I understand it correctly

has an undefined variable (s_Cluster0_uri) so presumably isn’t expected to compile as is. I replaced this with: mongoURI

mongoURI is constructed from mongoURIStr which looks something looking like
std::string mongoURIStr = "mongodb+srv://usermaster:@mytestcluster.bnmwf3b.mongodb.net/?retryWrites=true&w=majority

[I have no idea why putting a database password in a plaintext environmental variable would be more secure than one inside a compiled executable, although perhaps it’s just because people might not think to look there, so I simplified that out for the test code.]

the article lists “v_noabi” directories as required but they aren’t created by the vcpkg
so I will need to have a bit more of a play before it compiles, but hopefully this is forward movement

Hi @david_d ,

I’ve had a look at your article but since this directs to the original links
The links are for reference only. The article actually is independent in itself and does everything step by step.

Regarding the get-started-cxx/student-records-console-app/studentRecordsConsoleApp.cpp at main · mongodb-developer/get-started-cxx · GitHub,
Thanks for the catch. It was a typo. You did the right thing. It’s meant to be replaced with mongoURI. It should be fixed now in the github repo.

If you look at the code, mongoURIStr is actually fetched from an environment variable.

Regarding v_noabi directories - those are just includes that you should not need with vcpkg if you run
./vcpkg integrate install. The content of the v_noabi should however still be present under vcpkg folder - either in packages folder or installed folder.

Thanks @Rishabh_Bisht
Tried your tutorial and ultimately didn’t get any further than I had without it (although it was clearer and I wish I’d initially gone through that rather than the original one)
I did see that your code loads the uri from an environmental variable. I wasn’t clear what that adds? There don’t seem to be any security benefits and its an extra manual step to go wrong and it’s definitely not something which would be secure in a production environment. Given its a tutorial why not just have a string variable and just paste the autogenerated string into that (ie the one from the database deployment page? Cloud: MongoDB Cloud ). Much simpler than manually create an env variable with my database pasword exposed to any program which even happened to glance at env. So you’re teaching people a really bad! security habit.

Anyway I’ve now built with your tutorial and still get errors

I assume this one when building for the c-driver doesn’t matter?

>cmake --build . --config RelWithDebInfo --target install
...
  -- Installing: C:/Program Files/mongo-c-driver/lib/cmake/libmongoc-1.0/libmongoc-1.0-config-version.cmake
  -- Installing: C:/Program Files/mongo-c-driver/lib/cmake/libmongoc-static-1.0/libmongoc-static-1.0-config.cmake
  -- Installing: C:/Program Files/mongo-c-driver/lib/cmake/libmongoc-static-1.0/libmongoc-static-1.0-config-version.cma
  ke
  ******  B A T C H   R E C U R S I O N  exceeds STACK limits ******
  Recursion Count=289, Stack Usage=90 percent
  ******       B A T C H   PROCESSING IS   A B O R T E D      ******
  -- Installing: C:/Program Files/mongo-c-driver/share/mongo-c-driver/uninstall.cmd

Exception Unhandled:
When executing following the VS build get the following (very uninformative) error (this is the same as the furtherst point I managed when using the vkpkg files
Unhandled exception at 0x00007FF811A4CD29 in MongoCXXGettingStarted.exe: Microsoft C++ exception: mongocxx::v_noabi::operation_exception at memory location 0x000000ABE1CFE1A0.

Yeah, the “batch recursion exceeds limit” is a known issue and should be benign.

The exception you are seeing seem to be coming from the server. See the documentation here for reference - https://mongocxx.org/api/current/classmongocxx_1_1operation__exception.html

Can you try wrapping the getDatabases method in a try-catch and check what’s the error code/message you are getting in the exception?

Oh seriously! talk about amateur hour :frowning:
When I copied the Atlas URI I just replaced the word password with my password. I didn’t delete the bracketing <> so it was actually submitting the password as “”
I didn’t realise until I printed out the client variables and thought it was a bit odd that only the password was bracketed. So after deleting the bracketing <> it’s working now. For reference here are the quick t/c functions I used. I’ll expand these later - presumably the specific invalid password error is returned in raw_server_error?

With the simple t/c below I get:-
ERROR: getDatabases: bad auth : authentication failed: generic server error

With the mongoDB specific one:-
password:
username: myUsr
auth_source: admin
ERROR: getDatabases: bad auth : authentication failed: generic server error

vector<string> getDatabases(mongocxx::client& client)
{
	try {
		vector<string> cldn = client.list_database_names();
		for (auto& dn : cldn)
			cout << dn << "\n";
		return cldn;
	}
	catch (const std::exception& e) {
		std::cout << "ERROR: getDatabases: " << e.what() << std::endl;
		return {};
	}
}
#include <mongocxx/exception/operation_exception.hpp>
vector<string> getDatabases(mongocxx::client& client)
{

	cout << "password: " << client.uri().password() << std::endl;
	cout << "username: " << client.uri().username() << std::endl;
	cout << "auth_source: " << client.uri().auth_source() << std::endl;
//	cout << "appname: " << client.uri().appname().value() << std::endl;

	bool contains_err_info{ false };
	auto err_info = bsoncxx::builder::basic::document{}; 
	try {
		vector<string> cldn = client.list_database_names();
		for (auto& dn : cldn)
			cout << dn << "\n";
		return cldn;
	}
	catch (mongocxx::operation_exception const& e) {
		std::cout << "ERROR: getDatabases: " << e.what() << std::endl;
//		auto error = e.raw_server_error()->view();
//		auto result = error["writeConcernErrors"][0]["errInfo"];
//		contains_err_info = (err_info == result.get_document().view());
		return {};
	}
}

Glad to hear it’s working for you!

You could query e.code() and define a corresponding error in your application. Here is a map for error codes thrown by server - mongo/error_codes.yml at master · mongodb/mongo · GitHub
For reference, the situation you faced returns error code 11 (I reproduced it on my end) - UserNotFound

raw_server_error returns an optional. In case you want to make use of it, here’s a sample code - mongo-cxx-driver/transactions.cpp at master · mongodb/mongo-cxx-driver · GitHub

@Rishabh_Bisht
Sorry another crash with the tutorial - hopefully it’s a quick fix for you to answer.
The tutorial works well until I switch to a release build when it crashes on execution with a failed assert as the uri is contructed.
It builds with only one warning (as below - but this isn’t different for debug version).
[incidentally why did you make mongoURI global? There seems no need for this and it would seem to have been better to have declared it local to main.

static const mongocxx::uri mongoURI = mongocxx::uri{ mongoURIStr };
Debug Assertion Failed!

Program: C:\mongo-cxx-driver\bin\bsoncxx.dll
File: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include\xstring
Line: 1258

Expression: non-zero size null string_view


The build warning doesn’t appear to have any functional impact but is easily fixed by explicitly declaring the autos

1>C:\Users\dgm55\source\repos\MongoCXXGettingStarted\MongoCXXGettingStarted\MongoCXXGettingStarted.cpp(159,42): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
1>C:\Users\dgm55\source\repos\MongoCXXGettingStarted\MongoCXXGettingStarted\MongoCXXGettingStarted.cpp(159,42): message : while calling the constructor 'bsoncxx::v_noabi::view_or_value<bsoncxx::v_noabi::document::view,bsoncxx::v_noabi::document::value>::view_or_value(View)'
1>        with
1>        [
1>            View=bsoncxx::v_noabi::document::view
1>        ]
1>C:\mongo-cxx-driver\include\bsoncxx\v_noabi\bsoncxx\view_or_value.hpp(60,5): message : see declaration of 'bsoncxx::v_noabi::view_or_value<bsoncxx::v_noabi::document::view,bsoncxx::v_noabi::document::value>::view_or_value'

from

// Find the document with given key-value pair.
void findDocument(mongocxx::collection& collection, const string& key, const string& value)
{
	// Create the query filter
	auto filter = bsoncxx::builder::stream::document{} << key << value << bsoncxx::builder::stream::finalize;

	//Add query filter argument in find
	auto cursor = collection.find({ filter });

	for (auto&& doc : cursor)
	{
		cout << bsoncxx::to_json(doc) << endl;
	}
}

to

// Find the document with given key-value pair.
void findDocument(mongocxx::collection& collection, const string& key, const string& value)
{
	// Create the query filter
	bsoncxx::document::view_or_value filter = bsoncxx::builder::stream::document{} << key << value << bsoncxx::builder::stream::finalize;

	//Add query filter argument in find
	mongocxx::v_noabi::cursor cursor = collection.find({ filter });

	for (auto&& doc : cursor)
	{
		cout << bsoncxx::to_json(doc) << endl;
	}
}

I gave it a try on my end but can’t seem to reproduce with a release build. Is your code exactly same as tutorial for creating URI object from mongoURIStr or do you have done any local modifications?
You could move the URI creation inside main also if that helps. It was kept outside because I was going to do some checks on it in different part of the code but I later removed that part to keep the tutorial simple.