Qt undefined reference to 3rdparty software librar

2019-08-12 05:17发布

问题:

I using 3rd party library functions in my Qt application, but it's reporting errors such as "undefined reference to bp_attach collect2 : error: ld returned 1 exit status".

I have build 3rd party library (ion-dtn) from source code and did make & make install. I am certain that it has installed successfully in my Ubuntu system.

I have included its header file "bp.h" and Qt doesn’t complain about that. But when I compile I get the error mentioned above. Here is my .pro file:

QT       += core gui
QT       += network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = MYUDP
TEMPLATE = app

INCLUDEPATH += /usr/local/include/
LIBS += -L /usr/local/lib

PKGCONFIG +=ion-d
SOURCES += main.cpp\
        myudp.cpp

HEADERS  += myudp.h

FORMS    += myudp.ui

Path of "bp.h" where bp_attach function is declared is /usr/local/include/bp.h.

Libs for 3rd party library are installed in /usr/local/lib and is defined in .pro.

回答1:

Although you have told QMake where to find the headers and the libraries, you need to specify which libraries need to be linked. The QMake equivalent to LDLIBS is LIBS:

INCLUDEPATH += /usr/local/include
LIBS += -lbp


回答2:

Probably this will help:

LIBS += -L /usr/local/lib -l**You_library_Name**


标签: c++ qt qmake