dimanche 7 janvier 2018

mongocxx SegFault mac os x

I installed mongo-c and mongocxx as instructed. pkg-config out:

pkg-config --cflags libmongocxx
-I/usr/local/include/mongocxx/v_noabi -I/usr/local/Cellar/mongo-c-driver/1.9.0/include/libmongoc-1.0 -I/usr/local/include/bsoncxx/v_noabi -I/usr/local/Cellar/mongo-c-driver/1.9.0/include/libbson-1.0

CMake:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
###MONGODB
include_directories(${libmongocxx_INCLUDE_DIRS})
find_package(libmongocxx REQUIRED)
find_package(libbsoncxx REQUIRED)
include_directories(${LIBMONGOCXX_INCLUDE_DIR})
include_directories(${LIBBSONCXX_INCLUDE_DIR})
include_directories("/usr/local/include/mongocxx/v_noabi")
include_directories("/usr/local/include/bsoncxx/v_noabi")
include_directories("/usr/local/include/libmongoc-1.0")
include_directories("/usr/local/include/libbson-1.0")
include_directories("/usr/local/lib")
find_package(Boost REQUIRED COMPONENTS thread system)


add_executable(1MongoTest 1MongoTest.cpp)

The basic Code:

 #include <cstdint>
#include <iostream>
#include <vector>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/instance.hpp>
#include <string>


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;

using namespace std;

int main(int argc, char **argv) {


    mongocxx::instance instance{}; // This should be done only once.
    mongocxx::uri uri("mongodb://localhost:27017");
    mongocxx::client client(uri);

    mongocxx::database db = client["mydb"];
    mongocxx::collection coll = db["test"];

    std::cout << "passed " << endl;


    return 0;

I am getting segmentation fault when I run.

The problem line is:

    mongocxx::uri uri("mongodb://localhost:27017");

What am I doing wrong ? I am following the exact steps at the official site.?

Thanks

Aucun commentaire:

Enregistrer un commentaire