I am trying to follow the c++ driver installation tutorial here: https://www.mongodb.com/docs/languages/cpp/cpp-driver/current/get-started/
On step 3, when inputting
‘C:\Program Files\CMake\bin\cmake.exe’ …
-G “Visual Studio 16 2019” -A “x64”
-DCMAKE_CXX_STANDARD=17
-DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver
into the command prompt (the directory looks like C:\Windows\System32\mongo-cxx-driver-r4.0.0\build>) it outputs an error “The filename, directory name, or volume label syntax is incorrect.” Please, advice!
UPDATE: I have managed to install the driver as a package directly in the C++ project I am working on. I am working in Visual Studio 2019 Enterprize, with the v142 compiler. It required the inclusion of the boost library. I tried doing that both through NuGet packages in Visual Studio and installing boost v1.87 and 1.79 separately and linking them as dependencies. In all those cases, I get a compiler error that basically says the syntax is incorrect, even though the version of compiler matches the lib. The errors are many but here is the first one:
boost.1.83.0\lib\native\include\boost\throw_exception.hpp(97,36): error C2143: syntax error: missing ')' before 'constant'
Please let me know if someone encountered this before and what can be done!
What version of C++ driver are you using? I suggest using that latest (4.0) - it removes the need for boost.
Also, since you are using Visual Studio, consider using vcpkg for installing the driver - that should remove the need of manually building it from source
Thank you for a quick reply! I have followed the advanced tutorial you provided and installed the driver with vcpkg. I did every step except for “You can use the toolchain file…” as I don’t understand what it does or how to use it. I have created a console C++ application in Visual Studio 2022 and inserted the sample driver code from the C++ tutorial. But it cannot find the bsoncxx/mongocxx headers. I even included the paths to headers and libraries as shown in the advanced tutorial, but it still can’t find the files. What am I doing wrong?
If you execute vcpkg integrate install
, that should automatically integrate the headers and libs with VS.
Are the headers/libs showing up in your Include paths?
If not, can you manually add them (see screenshot below to see where to add them) and double check the the path you are setting actually has the required headers/libs?
Toolchain file parameter can be used to specify the path to vcpkg.cmake, to tell CMake where to find the development files like headers and libs, if you are building with CMake, see details below.
https://cmake.org/cmake/help/latest/variable/CMAKE_TOOLCHAIN_FILE.html
That did it! Thank you very much for your help! I’ll come back if I encounter any other issues.
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.