VS2019 x64 dll project build issues with mongo-cxx-driver-r3.8.0

Hi

I followed Getting Started with MongoDB and C++ | MongoDB
I have built the following correctly on windows 10.

  1. mongo-cxx-driver-r3.8.0
  2. mongo-c-driver-1.24.1
  3. boost_1_82_0

and I have all libs available now,

  1. mongocxx.lib
  2. bsoncxx.lib
  3. bson-1.0.lib
  4. bson-static-1.0.lib
  5. mongoc-1.0.lib
  6. mongoc-static-1.0.lib
  7. libboost_system-vc142-mt-gd-x64-1_82.lib
  8. libboost_filesystem-vc142-mt-gd-x64-1_82.lib
  9. libboost_thread-vc142-mt-gd-x64-1_82.lib
  10. libboost_date_time-vc142-mt-gd-x64-1_82.lib

Now I need to use Mongo DB c++ in the VS2019 x64 DLL project, I have all C++ include paths and lib paths and libs in linker when I include #include <mongocxx/client.hpp>
in my cpp file and building the project, I get many errors. look like this is only for a DLL project. is there any macro to define in the preprocessor? I already tried MONGOCXX_EXPORTS but still, the same errors appeared …

very 1st error

    create_collection_deprecated& max(std::int64_t max_documents)
Error (active)	E0106	invalid type for a bit field	DataBase	103		libs\mongo-cxx-driver-r3.8.0\src\mongocxx\options\create_collection.hpp
 find& max(bsoncxx::document::view_or_value max)
Error	C2146	syntax error: missing ')' before identifier 'max'	DataBase	301
\libs\mongo-cxx-driver-r3.8.0\src\mongocxx\options\find.hpp

I get errors in

  1. find_one_and_delete.hpp
  2. find_one_and_replace.hpp
  3. delete.hpp
  4. insert_many.hpp
  5. replace_one.hpp
  6. update.hpp
  7. collection.hpp

I guess the same issue is mentioned on another topic Can build console app with mongocxx but not DLL project VS2019

Hi @Galaxy_Core,

You may be colliding with the windows min and max macros.
What happens if you add #define NOMINMAX before #include <windows.h> in your code? Does the problem go away?

See this article for reference - The min/max problem in C++ and Windows

1 Like

I currently develop an C++ dll with vs2022 and mongo-cxx-driver-r3.9.0 running in win10. I think I have successfully installed the driver since I have successfully to develop my first mongo console app with vs2022. However, it is not for my current dll project. The error from VS2022 is showed below. Please kindly help to solve ‘>C:\VS_sln\Mongo_test\Mongo_test\include\bsoncxx\v_noabi\bsoncxx\builder\basic\impl.hpp(50,9): error C2668: ‘bsoncxx::v_noabi::builder::core::append’: ambiguous call to overloaded function
1>C:\VS_sln\Mongo_test\Mongo_test\include\bsoncxx\v_noabi\bsoncxx\builder\core.hpp(569,11): message : could be ‘bsoncxx::v_noabi::builder::core &bsoncxx::v_noabi::builder::core::append(int64_t)’
1>C:\VS_sln\Mongo_test\Mongo_test\include\bsoncxx\v_noabi\bsoncxx\builder\core.hpp(556,11): message : or ‘bsoncxx::v_noabi::builder::core &bsoncxx::v_noabi::builder::core::append(int32_t)’
1>C:\VS_sln\Mongo_test\Mongo_test\include\bsoncxx\v_noabi\bsoncxx\builder\core.hpp(543,11): message : or ‘bsoncxx::v_noabi::builder::core &bsoncxx::v_noabi::builder::core::append(double)’
1>C:\VS_sln\Mongo_test\Mongo_test\include\bsoncxx\v_noabi\bsoncxx\builder\core.hpp(530,11): message : or ‘bsoncxx::v_noabi::builder::core &bsoncxx::v_noabi::builder::core::append(bool)’
1>C:\VS_sln\Mongo_test\Mongo_test\include\bsoncxx\v_noabi\bsoncxx\builder\basic\impl.hpp(49,1): message : while trying to match the argument list ‘(unsigned int)’
1>C:\VS_sln\Mongo_test\Mongo_test\include\bsoncxx\v_noabi\bsoncxx\builder\basic\impl.hpp(54): message : see reference to function template instantiation ‘void bsoncxx::v_noabi::builder::basic::impl::generic_append<unsigned int&,void,void>(bsoncxx::v_noabi::builder::core *,T)’ being compiled
1> with
1> [
1> T=unsigned int &
1> ]’