Compiling cmus for cygwin

Posted on 21 Jan 2015 in Programming • 5 min read

cmus I work on a Windows machine for my dally job. On my personal desktop I use Arch Linux and i3 therefore my music player is in curses and does not need any mouse. In fact I use cmus. So I tried to replace my old media player clementine with cmus on Windows in cygwin.

For that we need to compile cmus from sources.

A TL;DR is available at the end of the article.

It is really easy, you just need to download the tar.gz archive, untar it, and run :

./configure
make
make install

Then cmus will be directly accessible in your cygwin environment. You can access a file explorer by pressing the 5 key and then navigate through your files and add a folder to your libarary with the a key. To know more about how to use cmus please refer to the official documentation.

Okay then why a whole blog post about 3 classical commands ? Well you may notice that when adding your folder(s) to your library not all your files are added to it, in fact cygwin does not package any mp3 codec so your flac files will be read by cmus but not the mp3 one (as long as you have install the flac codec).

In oder to read mp3 files with cmus we need to install (so to build) a library that read this file format: libmad

libmad

First of all we need to download the source package from the official web site : http://www.underbit.com/products/mad/ now we extract the files and make the classical commands:

./configure
make
make install

You may encounter the "guess build" error:

guess error

This append during the make command

configure: error: cannot guess build type; you must specify one

You may need the automake package and moreover you may need to replace the two old files config.guess and config.sub from libmad with the new ones downloadable at : ftp://ftp.gnu.org/pub/gnu/config/README

An other classical error is the -fforce-memi one:

-fforce-mem gcc error

This error is characterize by the following trace:

gcc: error: unrecognized command line option '-fforce-mem'
Makefile:383: recipe for target 'version.lo' failed
make[2]: *** [version.lo] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/user/Downloads/libmad-0.15.1b'
Makefile:424: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/cygdrive/c/Users/user/Downloads/libmad-0.15.1b'
Makefile:249: recipe for target 'all' failed
make: *** [all] Error 2

From GCC 4.3 release notes:

The -fforce-mem option has been removed because it has had no effect in the last few GCC releases.

So we need to remove this option from our configure script, some people wrote a patch for it but it is just a sed command

sed -i '/-fforce-mem/d' configure

We need to redo the 3 basics commands:

./configure
make
make install

At this point you should not have any error, but a classical one is the missing library error:

missing library error

The error is indicating the precise missing library (here libtool):

Makefile.am:27: Libtool library used but `LIBTOOL' is undefined
Makefile.am:27:
Makefile.am:27: The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
Makefile.am:27: to `configure.ac' and run `aclocal' and `autoconf' again.
Makefile:256: recipe for target 'Makefile.in' failed
make: *** [Makefile.in] Error 1

And we just need to install the missing library using cygwin package manager.

Now we have libmad install in /usr/local/lib/

cmus

But our installation is not completed we need to recompile cmus with the support of this new library and if you just launch the 3 basic commands it will not work. In fact, gcc does not search libraries in /usr/local by default. We need to add a flag at the configure step:

./configure CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib
make
make install

And now you can launch cmus and re-add your mp3 files and it works!

You can still have some erros, mostly with the newest cygwin versions.

recipe for target 'ape.o' failed

This error was first mention by buzzbo on github and resolved by mahkoh. Thanks to them.

After the ./configure, the make may output something like:

   CC     ape.o
In file included from ape.c:23:0:
xmalloc.h: In function 'xstrndup':
xmalloc.h:79:2: error: implicit declaration of function 'strndup' [-Werror=implicit-function-declaration]
  char *s = strndup(str, n);
  ^
xmalloc.h:79:12: warning: incompatible implicit declaration of built-in function 'strndup'
  char *s = strndup(str, n);
            ^
cc1: some warnings being treated as errors
scripts/lib.mk:66: recipe for target 'ape.o' failed
make: *** [ape.o] Error 1

This error is due to an implicit function declaration that is incorrect. Add this after all the includes of the offending files (xmalloc.h):

char *strndup(const char *s, size_t n);

Workflow - TL;DR

Here is the TL;DR.

  • Cygwin dependencies
  • flac-devel
  • ncurses

  • Install libmad

  • change the config.gess and config.sub files with the one from this readme
  • patch the configuration to not use the -fforce-mem option with sed: sed -i '/-fforce-mem/d' configure
  • run the 3 classical commands:

    • ./configure
    • make
    • make install
  • Install cmus from source and add the gcc flags to load libraries in /usr/local:

    • ./configure CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib
    • make
    • make install

If you run a classical linux distribution to install cmus use aptitude install cmus or pacman -S cmus. It is so much easier!

Disqus comments

This is a copy of the Disqus comments for this page

snapdeus - 2019

Thanks for this guide! I've been referring to it frequently.

I'm running into an issue trying to get .m4a files to work in cmus.

Have you had success with this?

So far, I've tried including libmp4v2.dll.a in /usr/local/lib, like you did with the libmad.a library, but that did not work.

I'm not aware of a good method for adding libraries to build dependencies - but that is my own fault.

maggick - 2019

Hi snapdeus, I didn't use cmus on Windows for a while. Probably the right library to decode .m4a is missing.

Abhishek upadhyay - 2017

Thank you very much for this awesome tutorial. I did exactly the same in babun and it worked! LOved it Thank you very much

James - 2017

Another post just to say thanks so much for this tutorial.

AerialB - 2015

Thank you so much for this. I am forced by circumstance to use Windows atm, and although I like foobar, cmus is just the best.

Lee - 2015

Thank you for minimizing a serious headache! Have you managed to get flac compatability figured out? I've not had much luck.

maggick - 2015

Thank you for your interest, flac compatibility is given with the flac codec package (the first one in the following capture) directly in the cygwin installer / package manager.

cygwin package manager