未定义引用`_imp___ZN10HTTPClient5abortEv'等

时间:2014-04-28 07:37:04

标签: c++ qt qt4 qt5 qmake

我正在将一个巨大的项目从Qt 4.x迁移到5,我差不多完成了但是我遇到了我无法找到的错误,我认为它与某些库的链接有关但我在这里有点迷失。我希望有人可以对这件事情说清楚。

错误:

  ./release\addeditaton.o:addeditaton.cpp:(.text+0x6ac2): undefined reference to `_imp___ZN10HTTPClient5abortEv'
    ./release\addeditaton.o:addeditaton.cpp:(.text+0x98c5): undefined reference to `_imp___ZN10HTTPClient3getE7QStringbb'
    ./release\addeditaton.o:addeditaton.cpp:(.text+0x9f88): undefined reference to `_imp___ZN10HTTPClient3getE7QStringbb'
    ./release\addeditaton.o:addeditaton.cpp:(.text+0xa7a8): undefined reference to `_imp___ZN10HTTPClient3getE7QStringbb'
    ./release\addeditaton.o:addeditaton.cpp:(.text+0xa921): undefined reference to `_imp___ZN10RestClientC2E7QStringibS0_S0_S0_S0_'
    ./release\addeditaton.o:addeditaton.cpp:(.text+0xc91b): undefined reference to `_imp___ZN10HTTPClient3getE7QStringbb'
    ./release\addeditaton.o:addeditaton.cpp:(.text+0xcaa3): undefined reference to `_imp___ZN10RestClientC2E7QStringibS0_S0_S0_S0_'
    ./release\addeditaton.o:addeditaton.cpp:(.text+0xe49d): undefined reference to `_imp___ZN10HTTPClient4postE7QStringS0_b'
    ./release\addeditaton.o:addeditaton.cpp:(.text+0xfc55): undefined reference to `_imp___ZN10HTTPClient4postE7QStringS0_b'
    Makefile.Release:922: recipe for target '..\Release\Swibz.exe' failed
    c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: ./release\addeditaton.o: bad reloc address 0x20 in section `.text$_ZN10QByteArrayD1Ev[__ZN10QByteArrayD1Ev]'

项目文件:

# ----------------------------------------------------
# This file is generated by the Qt Visual Studio Add-in.
# ------------------------------------------------------

TEMPLATE = app
TARGET = Swibz
include(Swibz.pri)
DESTDIR = ../Release
QT += widgets network xml webkit webkitwidgets opengl #core gui are by default
CONFIG += release
DEFINES += _WINDOWS QT_LARGEFILE_SUPPORT QT_XML_LIB QT_OPENGL_LIB QT_NETWORK_LIB QT_DLL QWT_DLL JSON_LIB_LIB
INCLUDEPATH += ../../../SprintLib \
    ./GeneratedFiles \
    ./GeneratedFiles/Release \
    . \
    #./../../Qwt/qwt-5.2.0/src \
    ../qwt/src \
    #../../../QENC/QENC \
    ../qenc \
   # ../../../zlib-1.2.5 \
    ../zlib-1.2.5 \
    #../../../serial/qextserialport-1.2win-alpha \
    ../qextserialport-1.2win-alpha \
   # ../../../qxmpp-0.3.0/src \
    ../qxmpp/build-qxmpp-Qt_4_8_5-Debug/src \
    #../../../JSON \
    ../json/JSON \
   # ../../../QtSerialPort/qtserialport/include
    ../QtSerialPort/qtserialport/include
LIBS += -L"../../../SprintLib/release" \
    -L"../../../QENC/release" \
    -L"../../../zlib-1.2.5/contrib/vstudio/vc9/x86/ZlibDllRelease" \
    -L"../../../serial/qextserialport-1.2win-alpha/Release" \
    -L"../../../qxmpp-0.3.0/lib" \
    -L"../../../JSON/Release" \
    -L"../../../QtSerialPort/qtserialport/src/serialport/release" \
    -lopengl32 \
    -lglu32 \
    -lgdi32 \
    -luser32 \
    #-lHDP \
    -L"./libHDP.a" \
    #-l../../Qwt/qwt-5.2.0/lib/debug/qwt5 \
    #-lqenc \
    #-lzlibwapi \
    -L"./zlib1.dll" \
    #-lqextserialport \
    -lsetupapi \
    #-lqxmpp \
    -L"./libqxmpp.a" \
    #-ljson_lib \
    #-lSerialPort1
    -L"./libqextserialportd.a" \
#DEPENDPATH += .
#MOC_DIR += ./GeneratedFiles/release
#OBJECTS_DIR += release
#UI_DIR += ./GeneratedFiles
#eRCC_DIR += ./GeneratedFiles
#win32:RC_FILE = Swibz.rc

TRANSLATIONS = ln_en.ts
TRANSLATIONS = ln_lv.ts
TRANSLATIONS = ln_lt.ts
TRANSLATIONS = ln_es.ts

CODECFORTR     = UTF-8

包含addeditaton.cpp(如果需要其余代码,请说明,它们是930行,我认为它们与问题无关(

#include "addeditaton.h"
#include "atonwidget.h"
#include "atoninfowidget.h"
#include "messagebox.h"

#include <QtDebug>
#include <QFileDialog>

2 个答案:

答案 0 :(得分:3)

您正在使用以下库的-L选项:

-L"./libHDP.a" \
-L"./zlib1.dll" \
-L"./libqxmpp.a" \
-L"./libqextserialportd.a" \

-L指定搜索库的目录。使用-l(小写)指定库。如果您想要指定确切的名称,则可能需要在libarary名称前添加冒号。例如,

-l :./libHDP.a  \
-l :./zlib1.dll \
-l :./libqxmpp.a \
-l :./libqextserialportd.a \

有关详细信息,请参阅https://sourceware.org/binutils/docs/ld/Options.html#Options

答案 1 :(得分:3)

  

./ release \ addeditaton.o:addeditaton.cpp :(。text + 0x6ac2):未定义引用`_imp ___ ZN10HTTPClient5abortEv&#39;

这样的行通常至少意味着以下任何一个问题:

  • 您没有安装相应的库。

  • 您没有使用您所依赖的符号安装正确的版本。

  • 您的关联选项设置不正确。

在这种情况下,抱怨是关于http客户端库的,所以让我们先检查你的项目文件。您在开始时正确使用了-L-l选项,但最终没有使用,所以让我们澄清它们的含义:

-L表示库的路径。

-l或者表示库名称或库的绝对路径。

现在,让我们看一下你在问题的最后写的内容:

-L"./libHDP.a" \
#-l../../Qwt/qwt-5.2.0/lib/debug/qwt5 \
#-lqenc \
#-lzlibwapi \
-L"./zlib1.dll" \
#-lqextserialport \
-lsetupapi \
#-lqxmpp \
-L"./libqxmpp.a" \
#-ljson_lib \
#-lSerialPort1
-L"./libqextserialportd.a" \

因此,您应该使用以下内容替换它:

-lHDP
#-l../../Qwt/qwt-5.2.0/lib/debug/qwt5 \
#-lqenc \
#-lzlibwapi \
-lzlib1 \
#-lqextserialport \
-lsetupapi \
#-lqxmpp \
-lqxmpp.a \
#-ljson_lib \
#-lSerialPort1 \
-lqextserialportd

或者,您也可以使用上面提到的-l选项指定静态库的绝对路径。

请注意,您不应混淆项目中的QtSerialPort和QextSerialPort等内容。最好使用QtSerialPort。