2017-06-19 37 views
0

我有下面的源代碼中的C++應用程序:C++可執行繼續尋找有序切入點

#include <cstdint> 
#include <iostream> 
#include <vector> 

#include <bsoncxx/json.hpp> 
#include <mongocxx/client.hpp> 
#include <mongocxx/stdx.hpp> 
#include <mongocxx/uri.hpp> 
#include <mongocxx/client.hpp> 
#include <mongocxx/instance.hpp> 

using bsoncxx::builder::stream::close_array; 
using bsoncxx::builder::stream::close_document; 
using bsoncxx::builder::stream::document; 
using bsoncxx::builder::stream::finalize; 
using bsoncxx::builder::stream::open_array; 
using bsoncxx::builder::stream::open_document; 

int main(int argc, char** argv) 
{ 
    std::cout << "\nJust to be sure!" << std::endl; 

    // Making a connection to Mongo 
    mongocxx::instance instance{}; 
    mongocxx::client client{mongocxx::uri{}}; 

    // Access a database 
    mongocxx::database db = client["results"]; 

    std::cout << "\ndone." << std::endl; 

    return 0; 
} 

我用下面的CMakeLists.txt文件編譯:

cmake_minimum_required(VERSION 3.7) 
project(testing) 

set(APP_SOURCES 
    test.cpp 
) 

link_directories(../../installed_mongocxx/lib) 
add_executable(testapp ${APP_SOURCES}) 
target_link_libraries(testapp mongocxx bsoncxx) 

target_include_directories(testapp PUBLIC 
          ../../installed_mongocxx/include/mongocxx/v_noabi 
          ../../installed_mongocxx/include/bsoncxx/v_noabi 
          E:/Softwares/Libraries/Boost/boost_1_64_0 
) 

install(TARGETS testapp 
     DESTINATION bin) 

我編譯程序使用Windows 10 64位上的MSBuild沒有錯誤,並在運行時出現此錯誤;

The ordinal 4694 could not be located in the dynamic library libmongoc-1.0.dll 

C++代碼或CMakeLists.txt有什麼問題可以解釋錯誤嗎?

+0

***這有什麼錯與C++代碼或CMakeLists.txt,可能是錯誤的解釋?***我說不,這是一個DLL confilct。一個例子是使用與導入庫不同的dll。 – drescherjm

+0

@drescherjm,我也同時編譯這些庫,所以我不認爲這是可能的。 – Amani

+0

您是否有機會在系統上安裝不同版本的libmongoc-1.0.dll? – drescherjm

回答

1

這不太可能。問題是你用來鏈接DLL的.LIB文件。當你建立一個DLL時,也會創建一個小的.LIB文件。這基本上只是一個目錄。如果將一個構建的.LIB文件與另一個構建的.DLL混用,則可能會遇到不兼容問題。

在這種情況下,.LIB文件將取自../../installed_mongocxx/lib,但.DLL可能不是。該DLL將在運行時通過Windows規則找到。

+0

知道了!我正在清理一切,重新開始。 – Amani

+0

我做了一切乾淨的構建。當從cmd運行可執行文件時,什麼都不會發生從WinDbg(64x)打開可執行文件時得到相同的錯誤信息。 – Amani

+0

@Amani:這表明你在第二種情況下找到了不同的DLL。 [DLL搜索規則](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v = vs.85).aspx) – MSalters

1

我注意到你最近一直在問一些與用mongocxx開發相關的問題,我鼓勵您在我們的mongodb-user Google Group或我們的Jira project上提出問題,這將使我們能夠更輕鬆地幫助您解決任何後續問題,而無需在多個地方進行對話。

(道歉張貼這作爲一個答案,而不是評論; StackOverflow上似乎有意見的長度上限,並在一個我可能不適合這個)

+0

真的很感激,因爲我真的希望在我的項目中使用Mongo C++。 – Amani