Click here to Skip to main content
11,932,780 members (58,233 online)
Click here to Skip to main content
Add your own
alternative version


21 bookmarked

Compiling SOX with Lame and Libmad for Windows

, 13 Jul 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Compiling SOX with Lame and Libmad for windows


This article shows how to compile sox with lame and libmad to enable mp3 support for Windows.


Many of us have an idea about the audio tool sox, through which one can edit the audio files in various formats. But it is pretty unfortunate for developers to find out that sox does not have mp3 support.  

Sox is an open source project of SourceForge, which was built on the source code of Lame, another open source. Now it is quite interesting that Lame does have mp3 support but sox does not. But sox has more audio editing features than lame, which makes sox so useful.

Now to enable mp3 support, we have to compile Sox with Lame and Libmad. Linux server has its process to compile, but Windows has its own way. If you Google this, you can find one basic article written by “Jason Smestad”. But when I tried that out I found some problems, some steps didn’t appear as they seemed to be written.

I don’t know why that happens, but I tried out a slightly different way after that and succeeded.

In this article, there is no credit for me, all credit goes to “Jason Smestad”, but I only publish this so that some developers like me may get it right.

Using the Code 


  1. Visual Studio 2005 / 2008
  2. Cmake 2.6
  3. Windows XP, SP-2 [It should work with others, but I haven’t tried]
  4. Sox 14.0.1
  5. Lame 3.97
  6. Libmad 0.15.1b

Step-1 [Compiling Lame]

  • Unzip the LAME source code and open it as a Visual Studio project.
  • Solution Explorer -> Right Click on libmp3lame -> Configuration Properties
    -> C/C++ -> Code Generation -> Runtime Library" -> Change the value to Multi-threaded DLL (/MD).
  • Solution Explorer -> Right Click on mpglib -> Configuration Properties
    -> C/C++ -> Code Generation -> Runtime Library" -> Change the value to Multi-threaded DLL (/MD)
  • Build libmp3lame
  • Build mpglib
  • Search libmp3lame.lib within that folder and rename it as mp3lame.lib
  • Create a folder outside and name it as you wish, for now let's consider, lameforsox
  • Create a folder inside it and name it as “lame” and now search “lame.h” within lame source code folder and copy that within this lame folder
  • Copy mp3lame.lib and mpglib.lib within lameforsox

Step-2 [Compiling Libmad]

  • Unzip the Libmad source code and open it as a Visual Studio project
  • Solution Explorer -> Right Click on each file of “source file” folder -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library" -> Change the value to Multi-threaded DLL (/MD)
  • Build Libmad
  • Search mad.h within that folder and copy it
  • Create another folder outside the application and name it as you wish. For now, let’s say “madforsox” and create another folder named “mad” within it.
  • Copy mad.h within “mad"
  • Search libmad.lib within Libmad source folder and rename it as mad.lib
  • Copy mad.lib within “madforsox

Step-3 [Compiling Sox with Lame and Mad Library]

  • Open Visual Studio. Tools -> Options -> Projects and Solutions -> VC++ Directories -> Include Directories -> Click on the “…” button -> now browse and add the lame.h and mad.h if these headers are not there.
  • Library Files -> click on “…” button -> add those lib files i.e. mp3lame.lib, mpglib.lib and mad.lib.
  • Visit sox source folder, find CMakeLists.txt
  • Open it and find if (NEED_LIBM)

    It should be within line number 62-65. Leave some space after that and add:

    optional(HAVE_LAME_LAME_H lame/lame.h mp3lame lame_init mp3) 

    And edit “lame/lame.h” to “lame.h”, i.e.: the line should look like this.

    optional(HAVE_LAME_LAME_H lame.h mp3lame lame_init mp3) 
  • Run -> Cmd -> change the path into Sox directory
  • Type  cmake.exe ./ -G "Visual Studio 9 2008" if you are using Visual Studio 2005, then  make it cmake.exe ./ -G "Visual Studio 8 2005"
  • If  everything is ok, then the following will appear:
    include files HAVE_MAD_H1 – found 
    mad_stream_buffer in madmad_stream_buffer in mad – found 
    include files HAVE_LAME_LAME_H1 – found 
    lame_init in mp3lamelame_init in mp3lame - found 
  • Now open Visual Studio and open the solution file [.sln] for sox
  • Rebuild “All Build”, if “File Modification Detected” appears then “Reload”, otherwise let the rebuild complete
  • Solution Explorer -> Right click on libsox -> "Preprocessor Definitions" (right click on libsox -> Properties -> Configuration Properties -> C/C++ -> Preprocessor) HAVE_STRING_H before the first line.  Set the "Runtime Library" to Multi-threaded DLL (/MD) as described above.
  • Do the same for sox after that Linker -> Input -> Additional Dependencies -> click on “…” button -> after the last line add mpglib.lib
  • Now build libsox
  • Build sox
  • Run -> cmd -> change to sox directory -> type sox –h
  • Now you will find "mp3, mp2" in the usage output in the section "SUPPORTED FILE FORMATS"

Points of Interest

I haven't tried with the latest version of sox. I might provide an update in the near future.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
India India
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionSox with AMR Pin
porcelli7-Apr-12 1:00
memberporcelli7-Apr-12 1:00 
Bugno flac? Pin
get8p11-Mar-12 8:44
memberget8p11-Mar-12 8:44 
QuestionIn visual studio 2010 how to compile the same code Pin
vikky4u18-Feb-12 10:32
membervikky4u18-Feb-12 10:32 
AnswerRuntime library needed (msvcr71.dll) Pin
eferreyra25-Apr-11 8:09
membereferreyra25-Apr-11 8:09 
GeneralUsing to extract and downgrade mp3 files first 30 seconds Pin
eferreyra25-Apr-11 4:22
membereferreyra25-Apr-11 4:22 
GeneralThanks Pin
iplogger14-Mar-10 8:18
memberiplogger14-Mar-10 8:18 
GeneralThank you! Pin
lenlynch15-Aug-09 18:59
memberlenlynch15-Aug-09 18:59 
GeneralCompiling Sox with Lame may not be worth it [modified] Pin
XenoLakitu27-Jul-09 0:20
memberXenoLakitu27-Jul-09 0:20 
GeneralRe: Compiling Sox with Lame may not be worth it Pin
arinhere9-Aug-09 19:59
memberarinhere9-Aug-09 19:59 
GeneralError when running on other computer Pin
presto1239-Jul-09 11:53
memberpresto1239-Jul-09 11:53 
GeneralRe: Error when running on other computer Pin
arinhere13-Jul-09 20:01
memberarinhere13-Jul-09 20:01 
GeneralLimbmad BUild Pin
presto1232-Jul-09 6:34
memberpresto1232-Jul-09 6:34 
GeneralRe: Limbmad BUild Pin
arinhere6-Jul-09 21:52
memberarinhere6-Jul-09 21:52 
GeneralSOX MP3 binaries Pin
igorbul7-Jun-09 2:00
memberigorbul7-Jun-09 2:00 
GeneralRe: SOX MP3 binaries Pin
presto12310-Jul-09 5:32
memberpresto12310-Jul-09 5:32 
GeneralRe: SOX MP3 binaries Pin
arinhere13-Jul-09 19:57
memberarinhere13-Jul-09 19:57 
GeneralRe: SOX MP3 binaries Pin
Alaa El Ghatit24-Jul-09 8:09
memberAlaa El Ghatit24-Jul-09 8:09 
Question14.0.2 ? Pin
X3m30-Apr-09 3:01
memberX3m30-Apr-09 3:01 
AnswerRe: 14.0.2 ? Pin
arinhere30-Apr-09 3:32
memberarinhere30-Apr-09 3:32 
Generalcaution in build Pin
bharat k28-Apr-09 6:24
memberbharat k28-Apr-09 6:24 
GeneralRe: caution in build Pin
arinhere30-Apr-09 3:27
memberarinhere30-Apr-09 3:27 
GeneralCompiling addition libraries Pin
haden.pereira26-Apr-09 23:12
memberhaden.pereira26-Apr-09 23:12 
GeneralRe: Compiling addition libraries Pin
arinhere27-Apr-09 1:34
memberarinhere27-Apr-09 1:34 
GeneralWin XP binary please Pin
kilroyjones13-Apr-09 12:21
memberkilroyjones13-Apr-09 12:21 
GeneralBugs in the guide Pin
Member 60381964-Apr-09 1:37
memberMember 60381964-Apr-09 1:37 
GeneralRe: Bugs in the guide Pin
haden.pereira26-Apr-09 23:14
memberhaden.pereira26-Apr-09 23:14 
QuestionThank you! Pin
tylocook10-Mar-09 20:24
membertylocook10-Mar-09 20:24 
QuestionRe: Thank you! Pin
tylocook10-Mar-09 20:27
membertylocook10-Mar-09 20:27 
AnswerRe: Thank you! Pin
arinhere11-Mar-09 21:15
memberarinhere11-Mar-09 21:15 
QuestionRe: Thank you! Pin
tylocook12-Mar-09 5:03
membertylocook12-Mar-09 5:03 
AnswerRe: Thank you! Pin
arinhere12-Mar-09 6:17
memberarinhere12-Mar-09 6:17 
AnswerRe: Thank you! Pin
tylocook12-Mar-09 12:03
membertylocook12-Mar-09 12:03 
GeneralRe: Thank you! Pin
arinhere12-Mar-09 19:44
memberarinhere12-Mar-09 19:44 
GeneralMy vote of 1 Pin
Ben Ratzlaff9-Mar-09 10:00
memberBen Ratzlaff9-Mar-09 10:00 
GeneralRe: My vote of 1 Pin
arinhere9-Mar-09 22:08
memberarinhere9-Mar-09 22:08 
QuestionWhat the final result can be used for? Pin
Tage Lejon9-Mar-09 6:43
memberTage Lejon9-Mar-09 6:43 
AnswerRe: What the final result can be used for? Pin
arinhere9-Mar-09 7:54
memberarinhere9-Mar-09 7:54 
GeneralMy vote of 1 Pin
Jim Crafton9-Mar-09 6:26
memberJim Crafton9-Mar-09 6:26 
QuestionASP.NET??? Pin
gstolarov9-Mar-09 6:18
membergstolarov9-Mar-09 6:18 
AnswerRe: ASP.NET??? Pin
arinhere9-Mar-09 7:57
memberarinhere9-Mar-09 7:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 14 Jul 2009
Article Copyright 2009 by arinhere
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid