user1876508
user1876508

Reputation: 13172

Why is the mongo C++ driver giving me compilation errors?

I have installed mongo straight from github using

sudo scons --full install

and have the following example source file

#include <cstdlib>
#include <iostream>
#include <mongo/client/dbclient.h>

void run() {
  mongo::DBClientConnection c;
  c.connect("localhost");
}

int main() {
  try {
    run();
    std::cout << "connected ok" << std::endl;
  } catch( const mongo::DBException &e ) {
    std::cout << "caught " << e.what() << std::endl;
  }
  return EXIT_SUCCESS;
}

When I run

g++ tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem 
-lboost_program_options -lboost_system -o tutorial

I am given the error

In file included from /usr/local/include/mongo/util/net/hostandport.h:21:0,
                 from /usr/local/include/mongo/util/net/message.h:24,
                 from /usr/local/include/mongo/client/dbclientinterface.h:30,
                 from /usr/local/include/mongo/client/connpool.h:23,
                 from /usr/local/include/mongo/client/dbclient.h:32,
                 from tutorial.cpp:3:
/usr/local/include/mongo/db/server_options.h:34:51: fatal error: 
mongo/util/options_parser/environment.h: No such file or directory
compilation terminated.

I looked into /usr/local/include/mongo/util, but the options_parser folder is not in there.

Upvotes: 0

Views: 637

Answers (1)

jazzhandsjeff
jazzhandsjeff

Reputation: 13

I had the same error myself, after following the write-up on MongoDB's website. What I ended up doing was copying the headers from the download directory to my include directory. I.e.

    sudo cp -R ~/Downloads/mongo-master/src/mongo/util/options_parser /usr/local/include/mongo/util/

Where mongo-master is the name of the extracted directory from MongoDB's GitHub. Hopefully this helps you.

Upvotes: 1

Related Questions