Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking error with taglib on Windows

I built taglib static libraries for Windows as follows. Gotto use mingw, not VS.

  1. Check out git clone https://github.com/taglib/taglib.git git_taglib
  2. Installed cmake with Win32 installer from cmake.org
  3. Configure 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. Compile mingw32-make.exe
  5. Install mingw32-make.exe install to C:\taglib_package

In my Qt project, I am using this library like thus

.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;

This leads to following link error

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'

The code works fine on a Mac. So I suppose the culprit is the lib. How should I compile the library to solve the above linking error?

like image 781
S B Avatar asked Oct 31 '22 14:10

S B


1 Answers

Use the -DTAGLIB_STATIC switch when compiling your code

like image 61
vitalyster Avatar answered Nov 15 '22 05:11

vitalyster