2017-06-19 39 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