问题描述
我在我的Qt应用程序中使用第三方库函数,但它报告错误,如未定义引用bp_attach collect2:错误:ld返回1退出状态
。 / p>
我已经从源代码生成第三方库(ion-dtn),并且 make
make install
。我确定它已经在我的Ubuntu系统中成功安装。
我已经包括它的头文件bp.h
和Qt不抱怨。但是当我编译我得到上面提到的错误。这是我的.pro文件:
QT + = core gui
QT + = network
greaterThan(QT_MAJOR_VERSION,4):QT + =小部件
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
bp.h的路径,其中声明了bp_attach函数 /usr/local/include/bp.h
。
第三方库的libs安装在 / usr / local / lib
中,并在.pro中定义。
虽然你告诉QMake在哪里找到头文件和库,你需要指定 which 图书馆需要链接。相当于 LDLIBS
的QMake为 LIBS
:
INCLUDEPATH + = / usr / local / include
LIBS + = -lbp
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.
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
这篇关于Qt未定义引用3rdparty软件库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!