2013-07-20 214 views
1

我想在我的機器上安裝MongoDB C++驅動程序。我按照指示here,並且一切都似乎安裝成功。不過,我似乎無法包含標題。下面是一個簡單的測試程序:Mongo C++驅動程序:mongo/client/dbclient.h:沒有這樣的文件或目錄

#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++ app/tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system -o tutorial 
app/tutorial.cpp:3:35: error: mongo/client/dbclient.h: No such file or directory 
app/tutorial.cpp: In function ‘void run()’: 
app/tutorial.cpp:6: error: ‘mongo’ has not been declared 
app/tutorial.cpp:6: error: expected `;' before ‘c’ 
app/tutorial.cpp:7: error: ‘c’ was not declared in this scope 
app/tutorial.cpp: In function ‘int main()’: 
app/tutorial.cpp:14: error: ISO C++ forbids declaration of ‘mongo’ with no type 
app/tutorial.cpp:14: error: expected `)' before ‘::’ token 
app/tutorial.cpp:14: error: expected `{' before ‘::’ token 
app/tutorial.cpp:14: error: ‘::DBException’ has not been declared 
app/tutorial.cpp:14: error: ‘e’ was not declared in this scope 
app/tutorial.cpp:14: error: expected `;' before ‘)’ token 

任何幫助將不勝感激。

+0

您需要將庫添加到編譯器的目錄中。 – 0x499602D2

回答

4

app/tutorial.cpp:3:35: error: mongo/client/dbclient.h: No such file or directory表示g ++找不到安裝的標題。在你的聯繫,下面的方框建議編譯命令狀態

You may need to use -I and -L to specify the locations of your mongo and boost headers and libraries.

的教程中,我會假設安裝過程中/usr/local/lib放在/usr/local/include和庫(例如libmongoclient.a)你的頭文件。然後,嘗試使編譯命令適應於讀取

g++ -I/usr/local/include -L/usr/local/lib -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system app/tutorial.cpp -o tutorial 
+0

感謝您的信息。不幸的是,我不認爲lib安裝正確。運行'sudo scons'後,'/ usr/local/lib'和'/ usr/local/install'都沒有mongo文件。 'scons'生成了一個包含.o文件和'libmongoclient.a'的構建目錄,我移動到了相應的位置,但沒有發生任何事情。 – Max

+0

嗯...你剛剛運行'sudo scons',還是有其他標誌你通過?如果我正確閱讀教程,則可能需要使用'sudo scons --prefix/usr/local --full install'。如果沒有「--full install」部分,我不確定這些文件是否將被正確安裝(可能它們只是構建但未安裝,這將解釋「.o」文件的存在)。你可以嘗試用這個命令重新安裝驅動程序,並檢查頭文件和庫文件的'/ usr/local/include'和'/ usr/local/lib'嗎? – 2013-07-20 02:21:59

+0

此外,爲了仔細檢查,你已經安裝了[MongoDB](http://docs.mongodb.org/manual/installation/)本身,對嗎? C++驅動程序首先要求。 (我會想象在'/ usr/local/bin'或'/ usr/bin'中有一個'mongo'二進制文件。) – 2013-07-20 02:27:06

相關問題