[已解决]MongoDB C++ /usr/local/include/boost/smart_ptr/scoped_ptr.hpp:97: T* boost::scoped_ptr::operator->() const [with T = mongo::AtomicWord]: Assertion `px != 0′ failed. Aborted (core dumped)

进行数据操作时报错:

quant_ctp_XTrader: /usr/local/include/boost/smart_ptr/scoped_ptr.hpp:97: T* boost::scoped_ptr<T>::operator->() const [with T = mongo::AtomicWord<unsigned int>]: Assertion `px != 0' failed.
Aborted (core dumped)

QQ截图20160803085225

解决办法:

在连接之前,加上:

mongo::client::initialize();

附上一段MongoDB的C++连接代码tutorial.cpp

#include <cstdlib>
#include <iostream>
#include <mongo/client/dbclient.h> // for the driver

void run() {
  mongo::DBClientConnection c;
  c.connect("localhost");
  mongo::DBClientConnection c1;
  c1.connect("localhost");
}

int main() {
    mongo::client::initialize();
    try {
        run();
        std::cout << "connected ok" << std::endl;
    } catch( const mongo::DBException &e ) {
        std::cout << "caught " << e.what() << std::endl;
    }
    return EXIT_SUCCESS;
}

编译脚本:

g++ -std=c++0x tutorial.cpp -pthread -lmongoclient -lboost_thread -lboost_system -lboost_regex -o tutorial

 

文章的脚注信息由WordPress的wp-posturl插件自动生成



|2|left
打赏

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: