【MongoDB VS2015 windows10下的C++开发环境搭建——亲妈级教程】

【MongoDB VS2015 windows10下的C++开发环境搭建——亲妈级教程】,第1张

class="superseo">MongoDB VS2015 windows10下的C++开发环境搭建(亲妈级教程)

长话短说 先上下载地址:MongoDBVS2015windows10下的C++开发环境搭建-C++文档类资源-CSDN下载

已经编译好的动态库地址:https://download.csdn.net/download/u011326153/85593418

总览

编译顺序:

(0)安装 mongodb-win32-x86_64-2008plus-ssl-3.4.23-signed.msi 傻瓜式一键安装

(1)libbson-1.9.2

(2)mongo-c-driver-1.9.2

(3)mongo-cxx-driver-releases-v3.2

其他:

VS2015(一般的即可,我的为up3) 、CMake 3.20(3.15以上即可 不拘泥于多少版本)、Boost 17.4(不用编译 直接头文件即可)

目录

总览

1、libbson-1.9.2

2、mongo-c-driver-1.9.2

3、mongo-cxx-driver-releases-v3.2

调试:

注:运行时生成的dll文件需要拷贝到exe所在文件夹中

1、libbson-1.9.2

 

2、mongo-c-driver-1.9.2

 新增方法如下:

需要用到,请仔细观察上图:

C:/Program Files/libbson/lib/cmake/libbson-1.0

C:/Program Files/libbson/lib/cmake/libbson-static-1.0

C:/Program Files/libbson/lib/bson-1.0.lib

C:/Program Files/libbson/lib/bson-static-1.0.lib

最终结果

3、mongo-cxx-driver-releases-v3.2

要使用上 前两步骤生成的全部lib和cmake下的文件,具体为

新增方法:

 最终结果

调试:
QT += core
QT -= gui

CONFIG += c++11

TARGET = untitled2
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

INCLUDEPATH += C:/boost
DEPENDPATH += C:/boost



win32:CONFIG(release, debug|release): LIBS += -L'C:/Program Files/libbson/lib/' -lbson-1.0
else:win32:CONFIG(debug, debug|release): LIBS += -L'C:/Program Files/libbson/lib/' -lbson-1.0d

INCLUDEPATH += 'C:/Program Files/libbson/include'
DEPENDPATH += 'C:/Program Files/libbson/include'

win32:CONFIG(release, debug|release): LIBS += -L'C:/Program Files/libbson/lib/' -lbson-static-1.0
else:win32:CONFIG(debug, debug|release): LIBS += -L'C:/Program Files/libbson/lib/' -lbson-static-1.0d

INCLUDEPATH += 'C:/Program Files/libbson/include'
DEPENDPATH += 'C:/Program Files/libbson/include'

win32:CONFIG(release, debug|release): LIBS += -L'C:/Program Files/libmongoc/lib/' -lmongoc-1.0
else:win32:CONFIG(debug, debug|release): LIBS += -L'C:/Program Files/libmongoc/lib/' -lmongoc-1.0d

INCLUDEPATH += 'C:/Program Files/libmongoc/include'
DEPENDPATH += 'C:/Program Files/libmongoc/include'

win32:CONFIG(release, debug|release): LIBS += -L'C:/Program Files/libmongoc/lib/' -lmongoc-static-1.0
else:win32:CONFIG(debug, debug|release): LIBS += -L'C:/Program Files/libmongoc/lib/' -lmongoc-static-1.0d

INCLUDEPATH += 'C:/Program Files/libmongoc/include'
DEPENDPATH += 'C:/Program Files/libmongoc/include'

win32:CONFIG(release, debug|release): LIBS += -L'C:/Program Files/libmongocxx/lib/' -lbsoncxx
else:win32:CONFIG(debug, debug|release): LIBS += -L'C:/Program Files/libmongocxx/lib/' -lbsoncxxd

INCLUDEPATH += 'C:/Program Files/libmongocxx/include'
DEPENDPATH += 'C:/Program Files/libmongocxx/include'

win32:CONFIG(release, debug|release): LIBS += -L'C:/Program Files/libmongocxx/lib/' -lmongocxx
else:win32:CONFIG(debug, debug|release): LIBS += -L'C:/Program Files/libmongocxx/lib/' -lmongocxxd

INCLUDEPATH += 'C:/Program Files/libmongocxx/include'
DEPENDPATH += 'C:/Program Files/libmongocxx/include'

INCLUDEPATH += 'C:/Program Files/libmongocxx/include/bsoncxx/v_noabi'
DEPENDPATH += 'C:/Program Files/libmongocxx/include/bsoncxx/v_noabi'

INCLUDEPATH += 'C:/Program Files/libmongocxx/include/mongocxx/v_noabi'
DEPENDPATH += 'C:/Program Files/libmongocxx/include/mongocxx/v_noabi'


#include 

#ifndef MONGODB_TOOL_OBJ_H
#define MONGODB_TOOL_OBJ_H

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::open_document;
using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::open_array;
using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::finalize;
using namespace mongocxx;
using namespace mongocxx::options;
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_document;
using bsoncxx::to_json;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QString m_hostName = "localhost";
    QString m_port     = "27017";


    mongocxx::instance* m_dbInstance = nullptr;
    mongocxx::client* m_client = nullptr;

    m_dbInstance = new(std::nothrow) mongocxx::instance();
    m_client = new(std::nothrow) mongocxx::client(mongocxx::uri{ ("mongodb://" + m_hostName + ":" + m_port).toStdString().c_str() });

    stdx::optional ret;
    QString db = "grid";
    QString coll = "";
    document doc;
    //doc.view()
    if (m_dbInstance && m_client)
    {
         //(*m_client)[db.toStdString().c_str()][coll.toStdString().c_str()].insert_one("1120");
    }



    return a.exec();
}

#endif
注:运行时生成的dll文件需要拷贝到exe所在文件夹中

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1329908.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-12
下一篇 2022-06-12

发表评论

登录后才能评论

评论列表(0条)

保存