Build the TagLib library with Visual Studio 2013

From Bitpost wiki

We'll use CMake to build, Visual Studio 2013 to compile.

First, make sure you have Visual Studio 2013 and the Microsoft Windows 8 SDK installed. Then use the CMake Win32 Installer from here. You should click ‘add to PATH’ when installing CMake (thanks Steve!).

TagLib has Zlib as a dependency. Get the taglib and zlib source code and unzip/untar and move them around to set up this structure:

c:\taglib
c:\taglib\taglib
c:\taglib\zlib

Now paste this script (originally from here and tweaked) into c:\taglib\build_taglib.bat and run it:

rem MDM This is a nice build script for taglib that I found here and adjusted:
rem MDM 	http://old.nabble.com/Cannot-compile-Taglib-for-x86-with-MSVC2010-td34048318.html#a34048899
rem MDM It pretty much does what we need out of the box.
rem MDM I am using the following tools and source files:
rem MDM
rem MDM		CMake windows installer cmake-2.8.9-win32-x86.exe
rem MDM		zlib 1.2.8 source
rem MDM		taglib 1.9.1 source
rem MDM
rem MDM Set things up here (don't try converting to deeper paths, they will fail):
rem MDM
rem MDM		c:\taglib\taglib
rem MDM		c:\taglib\zlib
rem MDM		c:\taglib\build_taglib.com (this file)
rem MDM

set ProgFilesRoot=%ProgramFiles%
set ProgFiles86Root=%ProgramFiles(x86)%
if not "%ProgFiles86Root%"=="" GOTO 64bitWindows
set ProgFiles86Root=%ProgramFiles%
:64bitWindows

set 64bitcl=true

if not exist "%ProgFiles86Root%\Microsoft Visual Studio 12.0\VC\bin\amd64\cl.exe" goto 32bitcl
set 64bitcl=false
:32bitcl


rem ######## zlib
cd zlib\

rem #Release x86
del ".\CMakeCache.txt"
rem old: call "%ProgFilesRoot%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Release /x86 /win7
call "%ProgFiles86Root%\Microsoft Visual Studio 12.0\VC\bin\vcvarsall.bat x86"
"%ProgFiles86Root%\CMake 2.8\bin\cmake" -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF .
nmake clean
nmake
mkdir .\Release\x86
move /Y zlib.lib .\Release\x86\zlib.lib

if "64bitcl"=="false" goto taglibrelease

rem #Release x64
del ".\CMakeCache.txt"
rem old: call "%ProgFilesRoot%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Release /x64 /win7
call "%ProgFiles86Root%\Microsoft Visual Studio 12.0\VC\bin\vcvarsall.bat x86_amd64"
"%ProgFiles86Root%\CMake 2.8\bin\cmake" -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF .
nmake clean
nmake
mkdir .\Release\x64
move /Y zlib.lib .\Release\x64\zlib.lib

cd ..\


:taglibrelease

rem ######## Taglib
cd taglib\

rem #Release x86
del ".\CMakeCache.txt"
rem old: call "%ProgFilesRoot%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Release /x86 /win7
call "%ProgFiles86Root%\Microsoft Visual Studio 12.0\VC\bin\vcvarsall.bat x86"
"%ProgFiles86Root%\CMake 2.8\bin\cmake" -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DZLIB_INCLUDE_DIR=..\zlib\ -DZLIB_LIBRARY=..\Release\x86\zlib.lib -DENABLE_STATIC=1 -DWITH_MP4=1 -DWITH_MP4=1 .
nmake clean
nmake
mkdir .\taglib\Release\x86
move /Y .\taglib\tag.lib .\taglib\Release\x86\tag.lib

if "64bitcl"=="false" goto taglibdebug

rem #Release x64
del ".\CMakeCache.txt"
rem old: call "%ProgFilesRoot%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Release /x64 /win7
call "%ProgFiles86Root%\Microsoft Visual Studio 12.0\VC\bin\vcvarsall.bat x86_amd64"
"%ProgFiles86Root%\CMake 2.8\bin\cmake" -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DZLIB_INCLUDE_DIR=..\zlib\ -DZLIB_LIBRARY=..\Release\x64\zlib.lib -DENABLE_STATIC=1 -DWITH_MP4=1 -DWITH_MP4=1 .
nmake clean
nmake
mkdir .\taglib\Release\x64
move /Y .\taglib\tag.lib .\taglib\Release\x64\tag.lib

:taglibdebug

rem #Debug x86
del ".\CMakeCache.txt"
rem old: call "%ProgFilesRoot%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Debug /x86 /win7
call "%ProgFiles86Root%\Microsoft Visual Studio 12.0\VC\bin\vcvarsall.bat x86"
"%ProgFiles86Root%\CMake 2.8\bin\cmake" -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -DZLIB_INCLUDE_DIR=..\zlib\ -DZLIB_LIBRARY=..\Release\x86\zlib.lib -DENABLE_STATIC=1 -DWITH_MP4=1 -DWITH_MP4=1 .
nmake clean
nmake
mkdir .\taglib\Debug\x86
rem MDM tagd.lib -> tag.lib
move /Y .\taglib\tag.lib .\taglib\Debug\x86\tag.lib
move /Y .\taglib\tag.pdb .\taglib\Debug\x86\tag.pdb

if "64bitcl"=="false" goto done

rem #Debug x64
del ".\CMakeCache.txt"
rem old: call "%ProgFilesRoot%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Debug /x64 /win7
call "%ProgFiles86Root%\Microsoft Visual Studio 12.0\VC\bin\vcvarsall.bat x86_amd64"
"%ProgFiles86Root%\CMake 2.8\bin\cmake" -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -DZLIB_INCLUDE_DIR=..\zlib\ -DZLIB_LIBRARY=..\Release\x64\zlib.lib -DENABLE_STATIC=1 -DWITH_MP4=1 -DWITH_MP4=1 .
nmake clean
nmake
mkdir .\taglib\Debug\x64
rem MDM tagd.lib -> tag.lib
move /Y .\taglib\tag.lib .\taglib\Debug\x64\tag.lib
move /Y .\taglib\tag.pdb .\taglib\Debug\x64\tag.pdb

:done

cd ..\

rem did that work?
pause

Now set up your project to use it!

I'm using Qt. First, add the include and lib paths to your Qt project .pro file:

win32 {
	CONFIG(Debug, Debug|Release) {
		win32:LIBS += "C:/taglib/taglib/taglib/Debug/x86/tag.lib"
	} else {
		win32:LIBS += "C:/taglib/taglib/taglib/Release/x86/tag.lib"
	}
}
# MDM For taglib headers
win32:INCLUDEPATH += "C:/taglib/taglib/taglib/Headers"

Then (re-)create your VS project if needed by opening the .pro file with the Qt Visual Studio Add-in.

Now include the header right before you use it - don't forget the #define or it won't be happy:

#define TAGLIB_STATIC
#include "taglib.h"
#include "mpegheader.h"
#include "mpegfile.h"

TagLib::MPEG::File file(str_song_filename.toStdString().c_str()); 
file.strip();
file.save();
// etc. or whatever...

Now build it on up! Have fun with it!