Build the TagLib library with Visual Studio 2010: Difference between revisions

From Bitpost wiki
No edit summary
No edit summary
Line 5: Line 5:
TagLib has Zlib as a dependency.  Get the [http://taglib.github.com/ taglib] and [http://zlib.net/ zlib] source code and unzip/untar and move them around to set up this structure:
TagLib has Zlib as a dependency.  Get the [http://taglib.github.com/ taglib] and [http://zlib.net/ zlib] source code and unzip/untar and move them around to set up this structure:


<pre><code>c:\taglib
<pre>c:\taglib
c:\taglib\taglib
c:\taglib\taglib
c:\taglib\zlib</code></pre>
c:\taglib\zlib</pre>


Now paste this script (originally from [http://old.nabble.com/RE%3A-Cannot-compile-Taglib-for-x86-with-MSVC2010-p34048422.html here] and tweaked) into <code>c:\taglib\build_taglib.cmd</code> and run it:
Now paste this script (originally from [http://old.nabble.com/RE%3A-Cannot-compile-Taglib-for-x86-with-MSVC2010-p34048422.html here] and tweaked) into <code>c:\taglib\build_taglib.cmd</code> and run it:


<pre><code>rem MDM This is a nice build script for taglib that I found here:
<code>rem MDM This is a nice build script for taglib that I found here:
rem MDM http://old.nabble.com/Cannot-compile-Taglib-for-x86-with-MSVC2010-td34048318.html#a34048899
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 It pretty much does what we need out of the box.
Line 130: Line 130:
rem MDM wow did that just work?
rem MDM wow did that just work?
pause
pause
</code></pre>
</code>


Now set up your project to use it!  First, add the lib to your project .pro file so the code gets linked in:
Now set up your project to use it!  First, add the lib to your project .pro file so the code gets linked in:

Revision as of 20:57, 4 October 2012

We'll use CMake to create a Visual Studio project file for the TagLib source so we can envoke the Visual Studio compiler. Weird, eh?

First, make sure you have Visual Studio 2010 and the Microsoft Windows SDK 7.1 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.cmd and run it:

rem MDM This is a nice build script for taglib that I found here: 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 fixed the tagd.lib copy line (it was using tag.lib before), that's about it. 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.27 source rem MDM taglib 1.8 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 10.0\VC\bin\amd64\cl.exe" goto 32bitcl set 64bitcl=false

32bitcl


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

rem #Release x86 del ".\CMakeCache.txt" call "%ProgFilesRoot%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Release /x86 /win7 call "%ProgFiles86Root%\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat" "%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" call "%ProgFilesRoot%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Release /x64 /win7 call "%ProgFiles86Root%\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat" "%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" call "%ProgFilesRoot%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Release /x86 /win7 call "%ProgFiles86Root%\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat" "%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" call "%ProgFilesRoot%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Release /x64 /win7 call "%ProgFiles86Root%\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat" "%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" call "%ProgFilesRoot%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Debug /x86 /win7 call "%ProgFiles86Root%\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat" "%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" call "%ProgFilesRoot%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Debug /x64 /win7 call "%ProgFiles86Root%\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat" "%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 MDM wow did that just work? pause

Now set up your project to use it! First, add the lib to your project .pro file so the code gets linked in:

<code>win32 {
	CONFIG(Debug, Debug|Release) {
		win32:LIBS += "C:/taglib/taglib/taglib/Debug/x86/tagd.lib"
	} else {
		win32:LIBS += "C:/taglib/taglib/taglib/Release/x86/tag.lib"
	}
}</code>

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

<code>#define TAGLIB_STATIC
#include "taglib/taglib/include/taglib.h"
#include "taglib/taglib/include/mpegheader.h"
#include "taglib/taglib/include/mpegfile.h"

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

Now build it on up! Have fun with it!