在Qt中添加外部库时出错“文件格式无法识别”

时间:2014-03-16 08:10:54

标签: c++ qt visual-c++ qt5 mingw32

我正在创建一个使用外部库的小型Qt应用程序。 我有头文件和lib文件。我的专业档案是

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = IndexCreator
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h


win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../ExternalLibrary/ -lHASHLIB
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../ExternalLibrary/ -lHASHLIBd

INCLUDEPATH += $$PWD/../ExternalLibrary
DEPENDPATH += $$PWD/../ExternalLibrary

我收到了这个错误:

12:01:11: Running steps for project IndexCreator...
12:01:11: Configuration unchanged, skipping qmake step.
12:01:11: Starting: "C:\Qt\Qt5.2.1\Tools\mingw48_32\bin\mingw32-make.exe" 
C:\Qt\Qt5.2.1\5.2.1\mingw48_32\bin\qmake.exe -spec win32-g++ -o Makefile ..\IndexCreator\IndexCreator.pro
C:/Qt/Qt5.2.1/Tools/mingw48_32/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'G:/Projects/PDT/IndexCreator/build-IndexCreator-Desktop_Qt_5_2_1_MinGW_32bit-Release'
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\IndexCreator.exe release/main.o release/mainwindow.o release/moc_mainwindow.o  -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmain -LG:/Projects/PDT/IndexCreator/IndexCreator/../ExternalLibrary/ -lHASHLIB -LC:\Qt\Qt5.2.1\5.2.1\mingw48_32\lib -lQt5Widgets -lQt5Gui -lQt5Core 
G:/Projects/PDT/IndexCreator/IndexCreator/../ExternalLibrary//HASHLIB.lib: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
Makefile.Release:80: recipe for target 'release\IndexCreator.exe' failed
mingw32-make[1]: *** [release\IndexCreator.exe] Error 1
mingw32-make[1]: Leaving directory 'G:/Projects/PDT/IndexCreator/build-IndexCreator-Desktop_Qt_5_2_1_MinGW_32bit-Release'
makefile:34: recipe for target 'release' failed
mingw32-make: *** [release] Error 2
12:01:13: The process "C:\Qt\Qt5.2.1\Tools\mingw48_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project IndexCreator (kit: Desktop Qt 5.2.1 MinGW 32bit)
When executing step 'Make'
12:01:13: Elapsed time: 00:02.

我需要使用此库中的函数。

1 个答案:

答案 0 :(得分:2)

似乎你正在混合mingw(你的工具链设置)和msvc(如何构建hashlib)。如果可能的话,在Windows上甚至是最新版本都应该以几乎所有成本避免这种情况。

由于您似乎无法访问源代码,如果您无法让供应商提供mingw版本,您最好删除项目的mingw,或者将hashlib作为依赖项。