I built taglib
Windows 的静态库如下。必须使用mingw,而不是VS。
- 查看
git clone https://github.com/taglib/taglib.git git_taglib
- 已安装
cmake
使用来自 cmake.org 的 Win32 安装程序
- 配置
cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=/C/taglib_package -DCMAKE_C_COMPILER=/C/MinGW4.4/bin/gcc.exe -DCMAKE_CXX_COMPILER=/C/MinGW4.4/bin/g++.exe -DENABLE_STATIC=ON -DENABLE_STATIC_RUNTIME=ON -DHAVE_ZLIB=0
- Compile
mingw32-make.exe
- Install
mingw32-make.exe install
to C:\taglib_package
在我的 Qt 项目中,我像这样使用这个库
.pro
INCLUDEPATH+="C:/taglib_package/include/taglib"
QMAKE_LIBDIR += "C:/taglib_package/lib"
LIBS+= -lz -ltag
.cpp
#include "fileref.h"
#include "taglib.h"
...
TagLib::FileRef f("Z:/Documents/sample.mp3");
TagLib::String artist = f.tag()->artist();
std::cout<< "Artist is " << artist << std::endl;
这会导致以下链接错误
release/main.o:main.cpp:(.text+0x93): undefined reference to `_imp___ZN6TagLib8FileNameC1EPKc'
release/main.o:main.cpp:(.text+0xb3): undefined reference to `_imp___ZN6TagLib7FileRefC1ENS_8FileNameEbNS_15AudioProperties9ReadStyleE'
release/main.o:main.cpp:(.text+0xdf): undefined reference to `_imp___ZNK6TagLib7FileRef3tagEv'
release/main.o:main.cpp:(.text+0x101): undefined reference to `_imp___ZN6TagLib6StringD1Ev'
release/main.o:main.cpp:(.text+0x10a): undefined reference to `_imp___ZN6TagLib7FileRefD1Ev'
release/main.o:main.cpp:(.text+0x210): undefined reference to `_imp___ZN6TagLib7FileRefD1Ev'
release/main.o:main.cpp:(.text+0x2bd): undefined reference to `_imp___ZN6TagLib6StringD1Ev'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [release\taglib_experiment.exe] Error 1
mingw32-make: *** [release] Error 2
19:56:21: The process "C:\MinGW4.4\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project taglib_experiment (kit: Desktop)
When executing step 'Make'
该代码在 Mac 上运行良好。所以我认为罪魁祸首是lib。我应该如何编译库来解决上述链接错误?
Use the -DTAGLIB_STATIC
编译时切换your code
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)