[CXX-1016] problem compiling helloworld.cpp Created: 04/Sep/16  Updated: 11/Sep/19  Resolved: 06/Oct/16

Status: Closed
Project: C++ Driver
Component/s: Build
Affects Version/s: 3.0.1
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Johnny Vana [X] Assignee: Unassigned
Resolution: Incomplete Votes: 0
Labels: c++
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

cmake-gui & VS2015



 Description   

I follow this tutorial https://github.com/mongodb/mongo-cxx-driver/wiki/Quickstart-Guide-(New-Driver).

I build and install bson and mongoc library.

When I build the hellomongo.cpp, I have this issue :
Error C2653 'mongocxx' : is not a class or a namespace name.

Thanks for helps !



 Comments   
Comment by Andrew Morrow (Inactive) [ 05/Oct/16 ]

Johnny - That looks like a problem with libmongo-c, not mongocxx. Could we move this discussion to mongodb-user? I really don't think there is a problem with the driver build system - we are running automated regression tests of the build on windows, so we know it works, and many other users have built the driver on windows. There doesn't seem to be a specific issue to be addressed in this ticket - more overall difficulty using CMake on Windows. Is it OK with you if I close this ticket and we move to mongodb-user?

Comment by Johnny Vana [X] [ 03/Oct/16 ]

I up to libmongoc 1.4.2.
When I generate a sln project with cmake-gui and add for BSON and BSON_INCLUDE_DIR : "C:\mongo-c-driver", I have this message :
WARNING: Target "test-replica-set" requests linking to directory "C:/mongo-c-driver". Targets may link only to libraries. CMake is dropping the item.
I link the libson librarie to c:/mongoc-driver as the howto :s

Comment by Johnny Vana [X] [ 26/Sep/16 ]

Yes, I build the install target in both Realease and Debug.
I clean up the solution and full rebuild but I stull have the same message

Comment by Andrew Morrow (Inactive) [ 25/Sep/16 ]

Johnny - Did you build the INSTALL target? See https://github.com/mongodb/mongo-cxx-driver/blob/master/appveyor.yml#L33. You need to do this so that the header files are properly installed somewhere. Note that you cannot simply rename config.hpp.in to config.hpp: the config.hpp.in file is a template file that CMake interpolates values into to produce a custom config.hpp header file. Once you have installed the driver somewhere (configure this with -DCMAKE_INSTALL_PREFIX argument to CMake), you should have a properly made config,hpp file.

Comment by Johnny Vana [X] [ 25/Sep/16 ]

I up to 3.0.2

I try and I think the compiler find the libson and libmongoc libraries.
But now, I have one another message when I compile the hellomongo.cpp : bsoncxx/config/config.hpp file does not exist.
I go into the directory and found config.hpp.in, I rename it config.hpp, and now VS says : invalid preprocessor command 'cmakedefine'

Comment by Andrew Morrow (Inactive) [ 24/Sep/16 ]

Hi Johnny - I'm closing this ticket as I think the errors you are getting are expected, and I've provided a workaround. If you need further help with this issue, please let us know and we can re-open the ticket.

Comment by Andrew Morrow (Inactive) [ 21/Sep/16 ]

Johnny - I think I know what is going on. You are linking against the static library version of libbsoncxx (I know this because the static version is installed as lib/libmongocxx.lib, whereas the .lib for the DLL is installed as lib/mongocxx.lib. When you link an application statically to the bsoncxx or mongocxx libraries, you must also link it to libbson and libmongoc, respectively. This is simply how static linking works - the libbsoncxx.lib and libmongocxx.lib static libraries only contain the symbols from the .cpp files that were compiled into it. The definitions for the libbson and libmongoc layer must be separately provided when linking your application. In general, the C++11 driver tries hard to make the use of libmongoc and libbson opaque, but it cannot do this at link time.

My recommendations are to either:

  • Switch your application to link against the dynamic versions of libbsoncxx and libmongocxx, which can record a runtime dependency against the underlying C driver and therefore do not propagate a need to specify the underlying C driver libraries to the application. OR
  • Add libbson and libmongoc as link libraries to your application.

Could you please try one of the above and let me know if it resolves the issues for you?

Comment by Johnny Vana [X] [ 20/Sep/16 ]

the first 10 errors are :

error LNK2019: symbole externe non résolu _bson_iter_init référencé dans la fonction "public: void __thiscall bsoncxx::v_noabi::builder::core::concatenate(class bsoncxx::v_noabi::document::view const &)" (?concatenate@core@builder@v_noabi@bsoncxx@@QAEXABVview@document@34@@Z)
bson_builder.obj : error LNK2019: symbole externe non résolu _bson_oid_init référencé dans la fonction __catch$?bson_eq_stream@@YAXPBU_bson_t@@ABVdocument@stream@builder@v_noabi@bsoncxx@@@Z$2
view.cpp.obj : error LNK2001: symbole externe non résolu _bson_iter_init
libbsoncxx.lib(oid.obj) : error LNK2001: symbole externe non résolu _bson_oid_init
view.cpp.obj : error LNK2001: symbole externe non résolu _bson_iter_init
bson_builder.obj : error LNK2019: symbole externe non résolu _bson_init référencé dans la fonction __catch$?bson_eq_stream@@YAXPBU_bson_t@@ABVdocument@stream@builder@v_noabi@bsoncxx@@@Z$2
core.obj : error LNK2019: symbole externe non résolu _bson_iter_next référencé dans la fonction "public: void __thiscall bsoncxx::v_noabi::builder::core::concatenate(class bsoncxx::v_noabi::document::view const &)" (?concatenate@core@builder@v_noabi@bsoncxx@@QAEXABVview@document@34@@Z)
libbsoncxx.lib(core.obj) : error LNK2001: symbole externe non résolu _bson_init
view.cpp.obj : error LNK2001: symbole externe non résolu _bson_iter_next
bson_builder.obj : error LNK2019: symbole externe non résolu _bson_destroy référencé dans la fonction __catch$?bson_eq_stream@@YAXPBU_bson_t@@ABVdocument@stream@builder@v_noabi@bsoncxx@@@Z$2
element.cpp.obj : error LNK2001: symbole externe non résolu _bson_iter_next
libbsoncxx.lib(core.obj) : error LNK2001: symbole externe non résolu _bson_destroy
view.cpp.obj : error LNK2001: symbole externe non résolu _bson_iter_next
bson_builder.obj : error LNK2019: symbole externe non résolu _bson_get_data référencé dans la fonction "void __cdecl bson_eq_stream(struct _bson_t const *,class bsoncxx::v_noabi::builder::stream::document const &)" (?bson_eq_stream@@YAXPBU_bson_t@@ABVdocument@stream@builder@v_noabi@bsoncxx@@@Z)
core.obj : error LNK2019: symbole externe non résolu _bson_free référencé dans la fonction "void __cdecl bsoncxx::v_noabi::builder::`anonymous namespace'::bson_free_deleter(unsigned char *)" (?bson_free_deleter@?A0xd4be65c7@builder@v_noabi@bsoncxx@@YAXPAE@Z)
libbsoncxx.lib(core.obj) : error LNK2001: symbole externe non résolu _bson_get_data
json.obj : error LNK2001: symbole externe non résolu _bson_free

Comment by Andrew Morrow (Inactive) [ 16/Sep/16 ]

Johnny - Could you please paste the first 10 or so errors from your new clean build?

Comment by Johnny Vana [X] [ 15/Sep/16 ]

the both compile.

I update VS2015 (update3.1), delete all driver files and restart compilation.
When I compile the mongocxx driver, I have 697 erros... It seems it comes from bson

Comment by Andrew Morrow (Inactive) [ 15/Sep/16 ]

Johnny - Which one is working, the one with the mongocxx/client.hpp include, or the one without? Could you try both?

Comment by Johnny Vana [X] [ 15/Sep/16 ]

If I compile your hello word code, it is working

Comment by Andrew Morrow (Inactive) [ 15/Sep/16 ]

Johnny - I believe that most recent error you posted has been fixed on the HEAD of the master branch, which is about to be released as 3.0.2. Could you please re-try with that. I still don't understand why you are getting messages that std::cout is not defined. What happens if you just reduce your example to just:

#include <iostream>
 
int main(int, char**) {
    std::cout << "Hello, World!\n" << std::endl;
}

What happens if you then extend it to:

#include <iostream>
#include <mongocxx/client.hpp>
 
int main(int, char**) {
    std::cout << "Hello, World!\n" << std::endl;
}

Comment by Johnny Vana [X] [ 12/Sep/16 ]

The first 3 errors are :
error C2017: séquence d'échappement non conforme,
error C3688: suffixe littéral non valide 'id1'; opérateur littéral ou modèle d'opérateur littéral 'operator ""id1' introuvable,
error C2661: 'Catch::ResultBuilder::ResultBuilder' : aucune fonction surchargée ne nécessite 3 arguments in file json.cpp at line 69.
So I comment the line 69, and have the 51 issues.

Comment by Andrew Morrow (Inactive) [ 10/Sep/16 ]

Johnny - Are these the first errors emitted in the build? Are there any earlier errors? In particular, errors about not being able to find headers to satisfy the #include statements? Also, please note that "error C2039: 'cout' : n'est pas membre de 'std'" is very strange - it suggests that the compiler doesn't even see cout as a member of the std namespace.

Comment by Johnny Vana [X] [ 07/Sep/16 ]

I have configured, built and installed the driver with cmake-gui and VS2015, not by batch.
The libson and c driver path is C:/mongo-driver/
The boost version is 1.61 and his path C:/user/johnny/desktop/boost_1.61/

The helloworld.cpp file :
#include <iostream>

#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>

#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>

int main(int, char**) {
mongocxx::instance inst{};
mongocxx::client conn{mongocxx::uri{}};

bsoncxx::builder::stream::document document{};

auto collection = conn["testdb"]["testcollection"];
document << "hello" << "world";

collection.insert_one(document.view());
auto cursor = collection.find({});

for (auto&& doc : cursor)

{ std::cout << bsoncxx::to_json(doc) << std::endl; }

}

I have 51 issue :s
error C2653: 'mongocxx' : n'est pas un nom de classe ni d'espace de noms
error C2065: 'instance' : identificateur non déclaré
error C2146: erreur de syntaxe : absence de ';' avant l'identificateur 'inst'
error C2065: 'inst' : identificateur non déclaré
error C2653: 'mongocxx' : n'est pas un nom de classe ni d'espace de noms
error C2065: 'client' : identificateur non déclaré
error C2146: erreur de syntaxe : absence de ';' avant l'identificateur 'conn'
error C2065: 'conn' : identificateur non déclaré
error C2065: 'uri' : identificateur non déclaré
error C2653: 'bsoncxx' : n'est pas un nom de classe ni d'espace de noms
error C2065: 'document' : identificateur non déclaré
error C2146: erreur de syntaxe : absence de ';' avant l'identificateur 'document'
error C2065: 'conn' : identificateur non déclaré
error C2065: 'document' : identificateur non déclaré
error C3536: 'collection' : ne peut pas être utilisé avant d'avoir été initialisé
error C2228: la partie gauche de '.insert_one' doit avoir un class/struct/union
note: le type est 'int'
error C2065: 'document' : identificateur non déclaré
error C2228: la partie gauche de '.view' doit avoir un class/struct/union
note: le type est 'unknown-type'
error C2228: la partie gauche de '.find' doit avoir un class/struct/union
note: le type est 'int'
error C3536: 'cursor' : ne peut pas être utilisé avant d'avoir été initialisé
error C3861: '<begin>' : identificateur introuvable
error C3312: aucune fonction 'begin' pouvant être appelée n'a été trouvée pour le type 'int'
error C3861: '<end>' : identificateur introuvable
error C3312: aucune fonction 'end' pouvant être appelée n'a été trouvée pour le type 'int'
error C2039: 'cout' : n'est pas membre de 'std'
\predefined c++ types (compiler internal)(209): note: voir la déclaration de 'std'
error C2065: 'cout' : identificateur non déclaré
error C2653: 'bsoncxx' : n'est pas un nom de classe ni d'espace de noms
error C2065: 'doc' : identificateur non déclaré
error C3861: 'to_json' : identificateur introuvable
error C2039: 'endl' : n'est pas membre de 'std'
predefined c++ types (compiler internal)(209): note: voir la déclaration de 'std'
error C2065: 'endl' : identificateur non déclaré

Sorry for the French language

Comment by David Golden [ 07/Sep/16 ]

Hello. Thanks for posting your issue. Could you please include the lines you used to configure, build and install the mongocxx driver? Also, could you please post the full helloworld.cpp file, the command line you used to compile it, and the full compiler output?

Thank you!

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