Como incluir uma biblioteca em um projeto Qt
Estou tentando criar um projeto que usa a biblioteca TagLib. Não tenho muita certeza de como exatamente fazer isso.
Eu baixeiTagLib 1.11.1.
Eu o construí da seguinte maneira:
Crie o zlib, primeiro fazendo com que o CMake crie um arquivo de solução do Visual Studio e, em seguida, crie essa solução com o Visual Studio:
mkdir build && cd build cmake .. -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX = "e: \ espaço de trabalho \ lib \ instalado" msbuild / P: Configuração = Depurar INSTALL.vcxproj msbuild / P: Configuração = Liberar INSTALL.vcxproj
Crie o TagLib da mesma maneira:
cd .... \ taglib-1.11.1 mkdir build && cd build cmake .. -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX = "e: \ espaço de trabalho \ lib \ instalado" -DZLIB_INCLUDE_DIR = "e: \ espaço de trabalho \ lib \ installed \ include "-DZLIB_LIBRARY =" e: \ espaço de trabalho \ lib \ instalado \ lib \ zlib.lib "-DWITH_ASF = em -DWITH_MP4 = em -DBUILD_EXAMPLES = no msbuild / P: Configuration = Release INSTALL.vcxproj
Eu crio um aplicativo simples do console Qt:
Eu adicionotag.lib
do TagLib Build acima emE:\workspace\lib\installed\lib
usando Qt
Qt -> Adicionar Biblioteca -> Tipo de Biblioteca(Biblioteca externa) -> .......
main.cpp:
#include <QCoreApplication>
#include <QDebug>
#include <taglib/fileref.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
TagLib::FileRef f("D:/Dire Straits - Sultans of Swing.mp3");
return a.exec();
}
taglibtest.pro
QT += core
QT -= gui
CONFIG += c++11
TARGET = taglibtest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$PWD/taglib/builds/ -ltag
else:win32:CONFIG(debug, debug|release): LIBS += -L$PWD/taglib/builds/ -ltagd
else:unix: LIBS += -L$PWD/taglib/builds/ -ltag
INCLUDEPATH += $PWD/taglib/builds
DEPENDPATH += $PWD/taglib/builds
win32:CONFIG(release, debug|release): LIBS += -L$PWD/taglib/builds/ -ltag
else:win32:CONFIG(debug, debug|release): LIBS += -L$PWD/taglib/builds/ -ltagd
else:unix: LIBS += -L$PWD/taglib/builds/ -ltag
INCLUDEPATH += $PWD/taglib/builds
DEPENDPATH += $PWD/taglib/builds
HEADERS += \
taglib/aifffile.h \
taglib/aiffproperties.h \
taglib/apefile.h \
taglib/apefooter.h \
taglib/apeitem.h \
taglib/apeproperties.h \
taglib/apetag.h \
taglib/asfattribute.h \
taglib/asffile.h \
taglib/asfpicture.h \
taglib/asfproperties.h \
etc....
etc....
Eu recebo os seguintes erros sempre que tento Construir o projeto no Qt:
F:\taglibtest\main.cpp:-1: error: undefined reference to `_imp___ZN6TagLib8FileNameC1EPKc'
F:\taglibtest\main.cpp:-1: error: undefined reference to `_imp___ZN6TagLib7FileRefC1ENS_8FileNameEbNS_15AudioProperties9ReadStyleE'
F:\taglibtest\main.cpp:-1: error: undefined reference to `_imp___ZN6TagLib7FileRefD1Ev'
F:\taglibtest\main.cpp:-1: error: undefined reference to `_imp___ZN6TagLib7FileRefD1Ev'
:-1: error: release/main.o: bad reloc address 0x0 in section `.ctors'
:-1: error: final link failed: Invalid operation
collect2.exe:-1: error: error: ld returned 1 exit status
O que devo fazer para corrigir isso e começar a trabalhar com o TagLib?
taglibtest.pro
QT += core
QT -= gui
CONFIG += c++11
TARGET = taglibtest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$PWD/taglib/builds/ -ltag
else:win32:CONFIG(debug, debug|release): LIBS += -L$PWD/taglib/builds/ -ltagd
else:unix: LIBS += -L$PWD/taglib/builds/ -ltag
INCLUDEPATH += $PWD/taglib/builds
DEPENDPATH += $PWD/taglib/builds
win32:CONFIG(release, debug|release): LIBS += -L$PWD/taglib/builds/ -ltag
else:win32:CONFIG(debug, debug|release): LIBS += -L$PWD/taglib/builds/ -ltagd
else:unix: LIBS += -L$PWD/taglib/builds/ -ltag
INCLUDEPATH += $PWD/taglib/builds
DEPENDPATH += $PWD/taglib/builds
HEADERS += \
taglib/aifffile.h \
taglib/aiffproperties.h \
taglib/apefile.h \
taglib/apefooter.h \
taglib/apeitem.h \
taglib/apeproperties.h \
taglib/apetag.h \
taglib/asfattribute.h \
taglib/asffile.h \
taglib/asfpicture.h \
taglib/asfproperties.h \
etc....
etc....