1

I am trying to connect MongoDb with Qt c++. When I build it there is no error, just information like;

:-1: warning: libboost_system.so.1.54.0, needed by /usr/local/lib/libboost_thread.so, may conflict with libboost_system.so.5

However when I tried to Run it says:

error while loading shared libraries: libboost_thread.so.1.54.0: cannot open shared object file: No such file or directory

Here is my small code sample which everything looks fine.

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDebug>
#include <mongo/client/dbclient.h>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    try
    {
        mongo::DBClientConnection c;
        c.connect("localhost");

        qDebug() << "Connected to Mongo";
    }
    catch (mongo::DBException &e)
    {
        qDebug() << "Cannot, Error : " << e.what();
    }

}

MainWindow::~MainWindow()
{
    delete ui;
}

Could you please help me why I am getting this error and how to fix it ?

EDIT :

Here is also my .pro file ;

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = mongodbtest
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

INCLUDEPATH += /usr/local/lib/

LIBS += -pthread \
    -lmongoclient \
    -lboost_thread \
    -lboost_system \
    -lboost_regex

and I see that I already have libboost_thread.so.1.54.0

[mg@mg-CentOS mg]$ locate libboost_thread.so.1.54.0 /usr/local/lib/libboost_thread.so.1.54.0

  • Does $LD_LIBRARY_PATH includes /usr/local/lib/ ? – soumen Jul 23 '15 at 8:41
  • what is the value of LD_LIBRARY_PATH? – Thushi Jul 23 '15 at 8:41
  • I set LD_LIBRARY_PATH but it says same.. While build there is no error just information, however in Run step it gives error. Sorry for mistyping before.. I editted my question – goGud Jul 23 '15 at 8:46
  • can you remove lboost_thread from LIBS and check? – Thushi Jul 23 '15 at 8:50
  • @Thushi When I remove it. In build step I get undefined errors (/usr/local/include/boost/system/error_code.hpp:222: error: undefined reference to boost::system::generic_category()') and :-1: error: collect2: ld returned 1 exit status` – goGud Jul 23 '15 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.