在Windows上将错误与taglib链接

时间:2014-11-12 14:35:01

标签: c++ linker mingw taglib

我为Windows构建了taglib个静态库,如下所示。得到了mingw,而不是VS.

  1. 查看git clone https://github.com/taglib/taglib.git git_taglib
  2. 使用来自cmake.org的Win32安装程序安装cmake
  3. 配置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
  4. 编译mingw32-make.exe
  5. mingw32-make.exe install安装到C:\taglib_package
  6. 在我的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。我应该如何编译库以解决上述链接错误?

1 个答案:

答案 0 :(得分:2)

在编译您的代码

时使用-DTAGLIB_STATIC开关