Compiling QEMU on Mac, or ANY Platform Isn’t Easy

by Mike Levin SEO & Datamaster, 05/24/2012

Well, compiling a static version of QEMU on Mac OS X is turning out to be much harder than I anticipated. First, I’m not a big compiler guy, so I’m not strong in debugging all the many moving parts that are in play here—and there are a lot.

Simple attempts to use ./configure reveal a world of dependencies from zlib to the gllib-2 libraries, all of which are met by installing MacPorts and each respective dependency. I also installed qemu itself through MacPorts just to assure myself it is possible to get a nice, modern QEMU on Mac without resorting to Q. It works, although I could only get the qemu-system-x86_64 to run, and not qemu-system-i386, which I would like to use for higher compatibility. But maybe that’ll be a concession I make—the Mac platform isn’t so heterogeneous as PCs, so sticking to 64-bit, but only for Mac, might not be so bad.

After playing around with patches that apparently have to do with case sensitivity of the file system, I finally got qemu to compile with dynamically linked shared libraries (the default) but that’s no good for a self-contained keychain version of qemu, because no one else is going to have those MacPort libraries on their machine… unless I can put all the dependencies inside a Mac OS X app package bundle, and make it look for its dependencies inside its own folders. That’s a possibility.

The first place that the dynamic linker should normally look for shared libraries is an executable’s preconfigured runtime library search path (if one exists). Therefore, I may still have to compile it myself, even going the dynamic library route, so that I can control where it looks for libraries. I hope it supports relative paths. There’s a trick with environment variables to force a binary you don’t have the source code for to look in a particular place for its libraries first, but its highly discouraged. But if I can only get qemu binaries working from things like MacPorts, that may be my best and only option.

Try getting some instant success by taking Mac out of the picture for a moment. Do this directly on your Commodore 64x, which is already Linux, and won’t have the MacPort issues. Endsure you have gcc… check! Download qemu from http://wiki.qemu.org/Download… check! Untarball it into home… check! Throw caution to the wind, and do a ./configure, make install

Got that same zlib dependency message as on Mac before I added all the dependencies through MacPorts. But on Linux, we start with…

apt-get install zlib1g-dev apt-get install libglib2.0-dev

Okay, I got both dependencies installed, and ./configure runs! Woot

I’m thinking better of using the default, and re-running config with graphics turned off and a specific target so I don’t create all those extra binaries…

./configure –target-list=i386-softmmu –disable-sdl

Excellent, ./configure still runs like a charm. However, I can’t get through the make procedure. I tried a bunch of things, such as disabling features to eliminate dependencies, and installing things to make the dependencies available, but with no success. Each platform that you compile on has its own unique challenges. I have to rethink my approach, and get back to some more urgent work. This is one of the pieces required in advancing towards my mission, but it’s a rather large hurdle. It looks like my strategy is going to be to gather up the libraries required, and putting them in a folder that qemu is forced to look at…

Okay, cd into /usr/bin… there’s qemu!

ldd ./qemu-system-x86_64 > /home/myname/deps.sh

…and edit it into a bunch of copy commands… and get the folder size… 24.4 MB! Ahhhhhh. That’s why the qemu binary is always so small. It’s LOADED with dependencies. I’m pretty optimistic about simulating a Mac OS X package bundle on any platform, using a script envelope to tell QEMU where to look for its dependencies first using the LD_LIBRARY_PATH environment variable, with a command like…

LD_LIBRARY_PATH=./linuxlibs export LD_LIBRARY_PATH

…or maybe better still, make it a temporary envelope around QEMU with…

env LD_LIBRARY_PATH=./linuxlibs qemu…

And for the record, those 24 MB of dependencies are…

/lib/i386-linux-gnu/librt.so.1 /lib/i386-linux-gnu/libglib-2.0.so.0 /lib/i386-linux-gnu/libutil.so.1 /usr/lib/librbd.so.1 /usr/lib/librados.so.2 /usr/lib/i386-linux-gnu/libcurl-gnutls.so.4 /lib/i386-linux-gnu/libncurses.so.5 /lib/i386-linux-gnu/libtinfo.so.5 /usr/lib/i386-linux-gnu/libasound.so.2 /usr/lib/i386-linux-gnu/libpulse.so.0 /usr/lib/i386-linux-gnu/libpulse-simple.so.0 /lib/i386-linux-gnu/libuuid.so.1 /lib/i386-linux-gnu/libpng12.so.0 /usr/lib/i386-linux-gnu/libsasl2.so.2 /usr/lib/i386-linux-gnu/libgnutls.so.26 /usr/lib/i386-linux-gnu/libSDL-1.2.so.0 /usr/lib/i386-linux-gnu/libX11.so.6 /lib/i386-linux-gnu/libaio.so.1 /lib/i386-linux-gnu/libm.so.6 /lib/i386-linux-gnu/libz.so.1 /lib/i386-linux-gnu/libpthread.so.0 /lib/i386-linux-gnu/libc.so.6 /lib/i386-linux-gnu/libpcre.so.3 /usr/lib/i386-linux-gnu/libstdc++.so.6 /lib/i386-linux-gnu/libgcc_s.so.1 /usr/lib/i386-linux-gnu/libnss3.so /usr/lib/i386-linux-gnu/libnspr4.so /usr/lib/i386-linux-gnu/libidn.so.11 /usr/lib/i386-linux-gnu/liblber-2.4.so.2 /usr/lib/i386-linux-gnu/libldap_r-2.4.so.2 /usr/lib/i386-linux-gnu/libgssapi_krb5.so.2 /lib/i386-linux-gnu/libgcrypt.so.11 /usr/lib/i386-linux-gnu/librtmp.so.0 /lib/i386-linux-gnu/libdl.so.2 /usr/lib/i386-linux-gnu/libjson.so.0 /usr/lib/i386-linux-gnu/libpulsecommon-1.1.so /lib/i386-linux-gnu/libdbus-1.so.3 /lib/ld-linux.so.2 /usr/lib/i386-linux-gnu/libtasn1.so.3 /usr/lib/i386-linux-gnu/libp11-kit.so.0 /usr/lib/i386-linux-gnu/libXext.so.6 /usr/lib/i386-linux-gnu/libcaca.so.0 /usr/lib/i386-linux-gnu/libxcb.so.1 /usr/lib/i386-linux-gnu/libnssutil3.so /usr/lib/i386-linux-gnu/libplc4.so /usr/lib/i386-linux-gnu/libplds4.so /lib/i386-linux-gnu/libresolv.so.2 /usr/lib/i386-linux-gnu/libgssapi.so.3 /usr/lib/i386-linux-gnu/libkrb5.so.3 /usr/lib/i386-linux-gnu/libk5crypto.so.3 /lib/i386-linux-gnu/libcom_err.so.2 /usr/lib/i386-linux-gnu/libkrb5support.so.0 /lib/i386-linux-gnu/libgpg-error.so.0 /lib/i386-linux-gnu/libwrap.so.0 /usr/lib/i386-linux-gnu/libsndfile.so.1 /usr/lib/i386-linux-gnu/libasyncns.so.0 /lib/i386-linux-gnu/libslang.so.2 /lib/i386-linux-gnu/libncursesw.so.5 /usr/lib/i386-linux-gnu/libXau.so.6 /usr/lib/i386-linux-gnu/libXdmcp.so.6 /usr/lib/i386-linux-gnu/libheimntlm.so.0 /usr/lib/i386-linux-gnu/libkrb5.so.26 /usr/lib/i386-linux-gnu/libasn1.so.8 /lib/i386-linux-gnu/librt.so.1 /lib/i386-linux-gnu/libglib-2.0.so.0 /lib/i386-linux-gnu/libutil.so.1 /usr/lib/librbd.so.1 /usr/lib/librados.so.2 /usr/lib/i386-linux-gnu/libcurl-gnutls.so.4 /lib/i386-linux-gnu/libncurses.so.5 /lib/i386-linux-gnu/libtinfo.so.5 /usr/lib/i386-linux-gnu/libasound.so.2 /usr/lib/i386-linux-gnu/libpulse.so.0 /usr/lib/i386-linux-gnu/libpulse-simple.so.0 /lib/i386-linux-gnu/libuuid.so.1 /lib/i386-linux-gnu/libpng12.so.0 /usr/lib/i386-linux-gnu/libsasl2.so.2 /usr/lib/i386-linux-gnu/libgnutls.so.26 /usr/lib/i386-linux-gnu/libSDL-1.2.so.0 /usr/lib/i386-linux-gnu/libX11.so.6 /lib/i386-linux-gnu/libaio.so.1 /lib/i386-linux-gnu/libm.so.6 /lib/i386-linux-gnu/libz.so.1 /lib/i386-linux-gnu/libpthread.so.0 /lib/i386-linux-gnu/libc.so.6 /lib/i386-linux-gnu/libpcre.so.3 /usr/lib/i386-linux-gnu/libstdc++.so.6 /lib/i386-linux-gnu/libgcc_s.so.1 /usr/lib/i386-linux-gnu/libnss3.so /usr/lib/i386-linux-gnu/libnspr4.so /usr/lib/i386-linux-gnu/libidn.so.11 /usr/lib/i386-linux-gnu/liblber-2.4.so.2 /usr/lib/i386-linux-gnu/libldap_r-2.4.so.2 /usr/lib/i386-linux-gnu/libgssapi_krb5.so.2 /lib/i386-linux-gnu/libgcrypt.so.11 /usr/lib/i386-linux-gnu/librtmp.so.0 /lib/i386-linux-gnu/libdl.so.2 /usr/lib/i386-linux-gnu/libjson.so.0 /usr/lib/i386-linux-gnu/libpulsecommon-1.1.so /lib/i386-linux-gnu/libdbus-1.so.3 /lib/ld-linux.so.2 /usr/lib/i386-linux-gnu/libtasn1.so.3 /usr/lib/i386-linux-gnu/libp11-kit.so.0 /usr/lib/i386-linux-gnu/libXext.so.6 /usr/lib/i386-linux-gnu/libcaca.so.0 /usr/lib/i386-linux-gnu/libxcb.so.1 /usr/lib/i386-linux-gnu/libnssutil3.so /usr/lib/i386-linux-gnu/libplc4.so /usr/lib/i386-linux-gnu/libplds4.so /lib/i386-linux-gnu/libresolv.so.2 /usr/lib/i386-linux-gnu/libgssapi.so.3 /usr/lib/i386-linux-gnu/libkrb5.so.3 /usr/lib/i386-linux-gnu/libk5crypto.so.3 /lib/i386-linux-gnu/libcom_err.so.2 /usr/lib/i386-linux-gnu/libkrb5support.so.0 /lib/i386-linux-gnu/libgpg-error.so.0 /lib/i386-linux-gnu/libwrap.so.0 /usr/lib/i386-linux-gnu/libsndfile.so.1 /usr/lib/i386-linux-gnu/libasyncns.so.0 /lib/i386-linux-gnu/libslang.so.2 /lib/i386-linux-gnu/libncursesw.so.5 /usr/lib/i386-linux-gnu/libXau.so.6 /usr/lib/i386-linux-gnu/libXdmcp.so.6 /usr/lib/i386-linux-gnu/libheimntlm.so.0 /usr/lib/i386-linux-gnu/libkrb5.so.26 /usr/lib/i386-linux-gnu/libasn1.so.8 /usr/lib/i386-linux-gnu/libhcrypto.so.4 /usr/lib/i386-linux-gnu/libroken.so.18 /lib/i386-linux-gnu/libkeyutils.so.1 /lib/i386-linux-gnu/libnsl.so.1 /usr/lib/i386-linux-gnu/libFLAC.so.8 /usr/lib/i386-linux-gnu/libvorbisenc.so.2 /usr/lib/i386-linux-gnu/libvorbis.so.0 /usr/lib/i386-linux-gnu/libogg.so.0 /usr/lib/i386-linux-gnu/libwind.so.0 /usr/lib/i386-linux-gnu/libheimbase.so.1 /usr/lib/i386-linux-gnu/libhx509.so.5 /usr/lib/i386-linux-gnu/libsqlite3.so.0 /lib/i386-linux-gnu/libcrypt.so.1