Mongodb connection #include problems

73 views
Skip to first unread message

Mathew Fok

unread,
Apr 20, 2014, 12:41:48 AM4/20/14
to mongod...@googlegroups.com
Hey guys, I got the mongoshell and Json file all set up. I need help connecting Mongodb to C++

I typed this in the command prompt but it gave a a syntax error. (my file name is ConnectorMain.cpp)

-I/usr/local/include -L/usr/local/lib -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system app/ConnectorMain.cpp -o ConnectorMain

This person had the same problem: http://stackoverflow.com/questions/17757683/mongo-c-driver-mongo-client-dbclient-h-no-such-file-or-directory

The reason that there you need to type this in the cmd pmt is because it will allow you to access the weird #inclue files like: #include "mongo/client/dbclient.h" 

I've visited http://api.mongodb.org/cplusplus/current/files.html

and this is the dbclient.h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#pragma once

#ifdef MONGO_EXPOSE_MACROS
#error dbclient.h is for C++ driver consumer use only
#endif
#define LIBMONGOCLIENT_CONSUMER
#include "mongo/client/redef_macros.h"
#include "mongo/pch.h"
#include "mongo/client/connpool.h"
#include "mongo/client/dbclient_rs.h"
#include "mongo/client/dbclientcursor.h"
#include "mongo/client/dbclientinterface.h"
#include "mongo/client/gridfs.h"
#include "mongo/client/init.h"
#include "mongo/client/sasl_client_authenticate.h"
#include "mongo/client/syncclusterconnection.h"
#include "mongo/util/net/ssl_options.h"

#include "mongo/client/undef_macros.h" 
and it is crazy cause of all the headers so I am trying to figure out how to hook this all up and as the forum says it has to do with setting up a -I or -L because it relates to this forumhttp://docs.mongodb.org/ecosystem/tutorial/getting-started-with-cpp-driver/#installing-the-driver-library-and-headers but that is in Linux.

Please help if you know how to do this.

Andrew Morrow

unread,
Apr 20, 2014, 6:26:23 PM4/20/14
to mongod...@googlegroups.com

Hi - 

The information you have provided below isn't really enough for us to know how to best help you. Could you please provide:

- The version of the C++ driver source you are using
- The host OS type and version, and toolchain and version you are using to compile
- The SCons invocation you used to build and install the driver from source
- The full compilation invocation for ConnectorMain.cpp
- The relevant section of ConnectorMain.cpp where the syntax error is generated
- The compiler output showing the syntax error

With this information we should be better able to determine how to fix your problem.

Thanks,
Andrew



--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/1fd07d9a-5ba8-47b8-84ea-a2788eb2f447%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mathew Fok

unread,
Apr 20, 2014, 8:58:46 PM4/20/14
to mongod...@googlegroups.com

C:\Users\MathewFok\Desktop>C:\Users\MathewFok\Downloads\mongodb-win32-x86_64-200
8plus-2.4.9\bin\MONGO.EXE
MongoDB shell version: 2.4.9
connecting to: test
> -I/usr/local/include -L/usr/local/lib -pthread -lmongoclient -lboost_thread-mt
 -lboost_filesystem -lboost_program_options -lboost_system app/ConnectorMain.cpp
 -o ConnectorMain
Sun Apr 20 00:10:30.022 SyntaxError: Unexpected identifier
>
///////////////I know your supposed to type it in the command promt and not use g++//////////////////////////////

C:\Users\MathewFok>mongo

MongoDB shell version: 2.4.9

connecting to: test

> show dbs

findata 5.951171875GB

local   0.078125GB

myJson  3.9521484375GB

> $ ./configure

Sat Apr 19 21:01:06.746 SyntaxError: Unexpected token /

> g++ -I/usr/local/include -L/usr/local/lib -pthread -lmongoclient -lboost_threa

d-mt -lboost_filesystem -lboost_program_options -lboost_system app/ConnectorMain

.cpp -o ConnectorMain

Sun Apr 20 00:50:43.974 SyntaxError: Unexpected identifier

Maybe I need to download boost or something? I'm using VS13 Express and my ConnectorMain is in my C:\Users\MathewFok\Documents\Visual Studio 2013\Projects\C++TradingAlgorithm\C++TradingAlgorithm folder as well as my dbcilent.h where I store any header I possibly need from the Mongodb C++ API website. 

Now that you can see where my files are stored, do you think you could help me make these include files work from the Mongodb C++ API website: http://api.mongodb.org/cplusplus/current/files.html. Thanks so much for responding!

Mathew Fok

unread,
Apr 20, 2014, 9:03:18 PM4/20/14
to mongod...@googlegroups.com

> -I/usr/local/include -L/usr/local/lib -pthread -lmongoclient -lboost_thread-mt

 -lboost_filesystem -lboost_program_options -lboost_system app/ConnectorMain.cpp

 -o ConnectorMain

Sun Apr 20 21:02:28.548 SyntaxError: Unexpected identifier

Mathew Fok

unread,
Apr 20, 2014, 9:06:28 PM4/20/14
to mongod...@googlegroups.com
I probably got the cmd line prompt wrong, but you have all my problems and issued addressed, so do you think you could come up with the proper command line prompt input to get this started. Thanks!

Andrew Morrow

unread,
Apr 21, 2014, 10:28:44 AM4/21/14
to mongod...@googlegroups.com
Hi -

If I have understood what you pasted above correctly, it appears that you are trying to compile your application from within the mongo shell. That will not work.

The steps to use the C++ driver are:

- Download the C++ driver source from the appropriate branch of (https://github.com/mongodb/mongo-cxx-driver)
- Follow the build instructions here: http://docs.mongodb.org/ecosystem/tutorial/download-and-compile-cpp-driver. Note that you should be running these commands in your command shell (assuming windows), and not in the mongo shell.
- Compile your application (again in the command shell, not the mongo shell), using a compiler invocation adorned with appropriate preprocessor and linker search paths to refer to the location where you installed the mongo driver.

Please let me know if you have any further questions.

Thanks,
Andrew





--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
Reply all
Reply to author
Forward
0 new messages