2013-10-08 65 views
0

我一直在使用爲什麼mongo C++驅動程序給我編譯錯誤?

sudo scons --full install 

,並具有以下示例源文件

#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; 
} 

當我運行

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

我給出的錯誤

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. 
安裝蒙戈直接從GitHub

我看着/ usr/local/include/mongo/util,但options_parser文件夾不在那裏。

回答

1

我在MongoDB網站上發表文章後,自己也有同樣的錯誤。我最終做的是將下載目錄中的頭文件複製到我的包含目錄中。即

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

其中mongo-master是從MongoDB的GitHub提取的目錄的名稱。希望這可以幫助你。