简体   繁体   中英

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

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

It seems you have twice the boost libraries in your path, and both seem to be in /usr/local/lib (not good).

Easiest solution is to use only one set of boost libraries if you can.

Else, the best setup would be achieved by installing boost in a specific (not global) location and linked to it (I'm not really familiar with qmake):

INCLUDEPATH  += /path/to/boost/boost_1_54_0/include
QMAKE_LIBDIR += /path/to/boost/boost_1_54_0/lib
LIBS         += -libboost_system.so.1.54.0  # relative link (preferred)
LIBS         += /path/to/boost/boost_1_54_0/lib/libboost_thread.1.54.0.so  # hard link
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM