MythTV on Windows

From MythTV Official Wiki

Revision as of 16:01, 5 November 2009 by Xebozone(talk | contribs)(I updated my website to be more general, and will try not to criticise or make assumptions again. I still acknowledge the fact that some of the information may not be correct, so I re-worded a bit.)

MythTV runs on Windows but currently an official exe is not provided, here is how to build a windows binary for yourself. It's not anything to do with "legal reasons", it's just that no-one has currently committed the time/space/bandwidth to continuously rebuild mythtv and host versions for download.

Using MinGW as the build platform, and MS Direct3D as the display layer.

Background & Caveats

MinGW/GCC doesn't seem to work well under Vista 64 bit (maybe even 32 bit too). Try compiling on an 2000/XP box instead.

What works?

The frontend, backend (without most tuners), and most utilities compile, and most functionality works.

What doesn't work?

There is currently no support for most tuners in mythbackend. However the network connected Template:HD Homerun ATSC, Cable or DVB-T tuner does work, as do a "virtual" tuner using a mpg file in a loop.

Win32 Build Script

The "HOWTO" section below is LONG, painful, and easy to get wrong (and definitely a bit out of date! ).
However, follow this first section, and you can ignore it! :-)

Note: If you are building 0.21-fixes instead of trunk, you must choose to install the "Previous" package when prompted by the MinGW Automated Installer. Failure to do so will result in build failure related to usleep(). This applies regardless of the version of build script or MinGW Automated Installer used.

run the Win32-packager.pl from a DOS command line ( be sure to use the correct options ).

WAIT FOR HOURS ( overnight)!

if the build was successful (a number of hours later)....

try to run the exe's that are located in the c:\mythtv\build\ folder.

if you used the -k option, check for an INSTALLER in c:\mythtv\setup\ )

Seriously... this script will (should) automatically download ALL the required downloads (into c:\msys\1.0\sources ) that are mentioned below, do all the compilations (hopefully), setup your environment, and save you at least 5 hours of click-download-click-save-click boring stuff. Occassionally the download links in the script don't work because external parties release new versions of their code, and remove the old ones, in this case, it should try to tell you, and you can manually download the newer version, and tweak the script to recognise it. You can usually work around this by pointing the script to a newer package. For example, fftw-3.1.2.tar.gz is no longer available. To fix this, you would edit the win32-packager.pl script, replacing fftw-3.1.2 with fftw-3.2.1, then run "c:/perl/bin/perl.exe -w win32-packager.pl" instead of MythInstaller.bat so that the change would not be overwritten. If for some reason, it is unable to extract the downloaded zip files, just unzip them by hand and re-run the script.

STOP! DON'T READ ANY FURTHER!. SERIOUSLY. IF YOUR BUILD DIDN'T WORK, PLEASE EMAIL THE PROBLEM TO THE mythtv-dev list, and the win32 devs will try to help!

You need only continue reading below if you are a masochist, or you want to understand all the steps that the above "win32-packager.pl" script will do for you.! Seriously, it will automatically do everything else listed in this HOWTO section for you, and a few usefull things besides.! PLEASE use it, and don't do it manually unless you absolutely must!

HOWTO

Outdated: The information on this page may no longer be relevant to the current release of MythTV, 29.0. Please consider helping to update it.

Conventions

Because this is a mixed-mode (unix tools on a windows box) installation document, there are times when you will be executing commands in "unix mode" (inside a msys window), and other times in "windows mode" (inside a "DOS Box" aka cmd.exe). This conventions section lays out how we identify when to do what.

Try to do most actions in a msys(unix) window, unless otherwise specified.

Commands that start with c:\xxx> are meant to be executed in a DOS Box, and the 'xxx' typically shows the folder you should be in, if important.

All dependencies/downloads will have at least two links: the first to the "main site/page" will be unlabeled, or labeled 'site:', and the second link will be labeled 'direct download:', to supply an immediate link to the software (or as immediate as possible + click-thru-instructions).

Sentences starting with TIP: or NOTE: are little pieces of positive information that you may find useful to know at this juncture, normally they are NOT about debugging/compiling issues, as these are covered in the "issues/problems" section at the bottom.

Install "MSYS base system" current release "MSYS-1.0.10.exe"

When instructed by msys (in a DOS window) enter the path where you installed MinGW in unix-style form:

c:/mingw

You might find that you get an error in "sync with child / child state waiting for longjump" or "Couldn't reserve space for cygwin's heap" when in the post-instllation (DOS window). This error definitely occurs with Vista 64 bit edition. The solution that I found to solve the problem, is to go to the MSYS Technology Preview download page and select the MSYS-1.0.11-20071204.tar.bz2 file:

Ensure that C Include Files / Lib Files are installed onto the local drive. (That is done by choosing a "custom" install, and just selecting that component to install as a minimum, if you plan on testing backend functionality too, you sjhould do a "complete" install, to install the mysql server too).

Copy all files from C:\Program Files\Mysql\Mysql Server 5.0\include to C:\MinGW\include

Note: The important thing is that #define STDCALL __stdcall is defined otherwise bad things will happen (it will compile but you'll fine segfaults happen immediately due to the stack getting well stacked.

Untick "When done unzipping open Setup.exe" - there is no need to install the SDK

click Unzip to extract it to C:\mssdk\temp

Click "OK" and "Close" when the program finishes extracting the files

Copy the following three files from SDK's include directory (C:\mssdk\temp\Include) ddraw.h dinput.h and dsound.h to the to the mingw include directory (C:\MinGW\Include)

Source Libs

For all the libs below, except when noted otherwise, use
tar xvzf xxxx.tar.gz, cd xxxxx,
./configure --prefix=/usr && make && make install
to build and install them, there's nothing special that needs to be done.

TIP: For those unfamiliar with libraries, using the shortname (eg 'ogg') normally refers to a download/library called 'libogg.xxxxx.tar.gz', or similar.

NOTE: For some reason, many people get get "ld.exe -lmp3lame not found" (or similar) when compiling mythtv if they install lame into /usr (by configuring with --prefix=/usr), even if the LD_LIBRARY_PATH variable is set correctly. Installing into /mingw seems to workaround this issue.

libpthread

This step details how you can compile libpthread from source (if needed)

NOTE: The patch fixes one critical bug, fixes one issue preventing it from working properly with bash, implements "install" in makefiles, and reduces number of compiler warnings during MythTV compilation.
Unfortunately, this breaks QT build scripts, but it still allows to build the qt-mt3.dll properly.

Rename sh.exe OR check path

QT doesn't like sh.exe:
To get the QT build to work temporarily rename the sh.exe which MINGW and MSYS use.

c:\>rename \MSYS\1.0\bin\sh.exe sh_.exe
c:\>rename %MINGW%\bin\sh.exe sh_.exe # may not exist, but if it does, rename it.

Alternatively, some people have just removed msys or cygwin from their path.

TIP: I get errors about not finding cp or rm when I do NOT have c:\msys\bin in my path. -- zack

Compile and build QT

NOTE: Background information on what is happening here:

The configure.bat first creates link_includes.exe and configure.exe which are needed for
bootstrap the build process. link_includes.exe copies all relevant Qt headers into the
include-directory. configure.exe is the replacement for the ./configure-script unter
Unix/Linux. After that, qmake.exe is built and the compilation gets started.

Next we need to configure and build the source - This should build the whole Qt release:

This is due to a QT dependency (uic.exe) not being compiled and, later, libqassistantclient not being compiled before it is required, and a missing makefile in tools\linguist\tutorial The workaround is as follows:

NOTE: I've re-done this area of the compile multiple times... would appreciated the above workaround being tested by a third party -- Richard Dale
Richard - I was unable to repeat your error, and my QT builds fine so long as I apply the qt.patch.gz file (as per the instructions) immediately after I extract the qt. - Buzz.

I(Buzz) created a batch file for building QT, I called it qtsetup.bat:
(this is the contents of the batch file)

Also, if you get an error like "qatomic_windows.h: error: declaration of C function `long int InterlockedCompareExchange(long int*, long int, long int)' conflicts with winbase.h: error: previous declaration `LONG InterlockedCompareExchange(volatile LONG*, LONG, LONG)' here", then you'll have to fix the QT4 file \src\corelib\arch\qatomic_windows.h as per the above thread. Specifically, you have to change this block:

Test Running Mythtv

script to assemble it all together

After successfully running 'make' you might want to try/test running mythtv and/or your 'make install' may not work.
I made a quick shell script to copy all the (aparently) needed .exe and .dll files into the same folder, so that mythfrontend will at least start (even if it does still crash before starting any sort of GUI):

You can now run the mythfrontend.exe from /c/mythtv/mythtv/run/mythfrontend.exe

I note that this copies the dlls from the filters subdirectory into run/
Should they go in a filters/ subdirectory?
You also copy the linqsqlmysql.dll into the run/ directory as well as sqldrivers/
This did not work for me. -- Simon

first test run

Run ./run/mythfrontend.exe now (from msys, or DOS, or windows is fine), and it will probably complain "Unable to connect to database!" among other errors/debug.

mysql.txt

Create/copy a mysql.txt file that specifies the connection parameters for a mythtv mysql database, and copy it into the ./run/ folder, and try again!

Installing MySQL Server

Next, you need to actually need to have a mysql server running, and configured to accept the username,password, and database that you specified in the mysql.txt!

You can configure your database on a different (eg existing) mysql server/box (like a linux box), but I STRONGLY urge you to NOT to point it to any existing mythty database without taking a backup first, and realising that you will quote probably break any other mythtv install connected to that database (due to the schema differences in different versions )!

MySQL Community Edition Server - optional (but you need a mysql server of some sort!)

Download the installer
Run it.
Follow the prompts
Configure the instance (if it doesn't start at the end of the install, go to Start->All Programs->MySQL->MySQL Server 5.0->MySQL Server Instance Config Wizard. )
Be sure to have mysql "Start/Run as a service"
Remember the "root password" that you choose.

After the changes just start the MythInstaller.bat script again and compilation should work.

During QT compile process

QT compile failed it could not find mysql.h

Solution: In mysql.h, there are lines that start with something like "MinGW supports unix API" - make sure you comment or remove them or you will be getting segfaults because the functions will be declared as stdcall when they are cdecl
(or something close to it) - Andrei

Andrei - I can't find this information - could you please dig out your mysql.h and provide further details -- Richard Dale

There is no supplied libmysql.a

There are some issues with the mysql package in that there is no supplied libmysql.a

QT issue: Are you saying that i don't need to do any of this reimp/dlltool nonsense?

Comments/Solution: Yes, that's what I'm saying. I had more problems with the import libraries than without them. One of the changes I made to qmake's mkspec is to stop generating them. - Andrei ( I think Andrei was refering to the QT patch on Ticket #4270 ?? - Buzz)

uic.exe cannot be found

During QT compilation uic.exe cannot be found, with the following error message:

Comments/Solution: I'm not sure why this happens as I had one install of msys work fine and then same error as you.
In the end I had to cd into /msys/qt-3/src and edit the Makefile and add -I"c:/msys/qt-3/src/tmp/moc/release-shared-mt"
on the INCPATH line (I have the qt-3 src at c:/msys).

This isn't working because during compiling process script writes new Makefile over the last one.
I managed to get rid of this error by editing file C:\MSys\1.0\qt-3.3.x-p8\qmake\generators\win32\mingw_make.cpp:
Replace section:

Should be there, otherwise everything seems to compile properly, but doesn’t work (stdcall functions are called as cdecl, stack pointer does not get restored, you get almost immediate segfaults after a couple of mysql function calls, but not immediately in the mysql call itself). I spent hours trying to figure this out. I think this was also a problem of earlier Cygwin build attempts.

We also need to disable the section in /mingw/include/mysql.h that disables winsock.h so it's always included.

ie Comment out (insert //) in the two lines (one in front and 1 after) "#include <winsock.h> in /mingw/include/mysql.h so it now reads:

Solution: This should be fixed by the mysql.h patch above and the proposed solution should not be needed! Looks like it can't find the mysql library (libmysql.a). Follow the steps precisely in the MySQL section above (particularly the reimp section) to create libmysql.a

ld.exe cannot find library -lmysql.lib

Solution: Looks like the qt patch (I used the combined patch) is missing a change to the qt-3.3.x-p8/plugins/src/sqldrivers/mysql/mysql.pro file for removing the .lib from the library links. I just edited the Makefile manually and changed -lmysql.lib to -lmysql --zack

ERROR! You must have FreeType installed to compile MythTV

I have compiled all of the dependencies and such but when I go to run the configure script for myth I get:

"ERROR! You must have FreeType installed to compile MythTV."

Solution:

Have you installed freetype with "make install"? Do you have libfreetype-6.dll in your mingw bin
directory and freetype2/freetype in your include directory?

I installed the libraries directly to the mingw installation: "./configure --prefix=/mingw && make && make install" - zack

Comment: I have confirmed the problem named above occurs when you use "--prefix=/usr", and Zacks solution
fixes it. no idea why though, as my LD_LIBRARY_PATH specify both. - Buzz.

Linker complains about not finding libs=

When compiling mythtv the linker complains about not finding libs.

Solution: You either haven't installed the prerequisite libraries or you haven't set the LD_LIBRARY_PATH environment variable

dsound.h not found

In file included from audiooutput.cpp:13:
audiooutputdx.h:9:39: dsound.h: No such file or directory
audiooutputdx.h:34:2: warning: #warning Several methods in AudioOutputDX need to be implemented...
In file included from audiooutput.cpp:13:
audiooutputdx.h:60: error: `LPDIRECTSOUND' does not name a type
audiooutputdx.h:61: error: `LPDIRECTSOUNDBUFFER' does not name a type
audiooutputdx.h:64: error: `LPDIRECTSOUNDNOTIFY' does not name a type
audiooutputdx.h:65: error: `DSBPOSITIONNOTIFY' does not name a type
make[2]: *** [audiooutput.o] Error 1
make[2]: Leaving directory `/c/mythtv/mythtv/libs/libmyth'
make[1]: *** [sub-libmyth] Error 2
make[1]: Leaving directory `/c/mythtv/mythtv/libs'
make: *** [sub-libs] Error 2

Solution: You don't have the "directX header files" - please install these as per the above!

At MythTV runtime

Mythtv dies when starting with a NO SQL drivers message

Solution:

cd $QTDIR/lib && cp ../plugins/sqldrivers/libqsqlmysql.dll .

If you don't have a dll called plugins/sqldrivers/libqsqlmysql.dll in the plugins/sqldrivers folder of your qt build, then it's possible that your c:\MingW\include\mysql.h file is incorrect (which sometimes allows qt to build, but prevents this specific dll from appearing as it should).

QSocketNotifier never generates signals

During debugging, I found one more bug in QT: QSocketNotifier never generates "signals" for listening sockets, which effectively prevents anything that listens incoming connections (mythbackend and possibly UPNP code in mythfrontend too) from accepting them. - Andrei (was this you?)

Alternate solution. I encountered a problem that my qt make was not creating the appropriate MYSQL drivers.

To test the the QT MYSQL driver, I used the examples/sql/blob program.
Change line 16 in main.cpp to read #define DRIVER "QMYSQL3"
Run make and blob.exe (from mingw or DOS window)
If you get an error about no Drivers found, QT has not built the plugin correctly.

To build the drivers manually:
Make sure you have MySQL installation files with the Libs & Include Files
Build the plugin as follows (here it is assumed that MySQL is installed in C:\MYSQL):
cd %QTDIR%\plugins\src\sqldrivers\mysql
qmake -o Makefile "INCLUDEPATH+=C:\MYSQL\INCLUDE" "LIBS+=C:\MYSQL\LIB\OPT\LIBMYSQL.LIB" mysql.pro
mingw32-make
Then copy libqsqlmysql.dll to the run directory

Mythfrontend reports could not blit surface

Starts OK but when you try to display video you see:

2007-12-29 12:29:15.828 could not blit surface (error 80004005)

I see this in vmware/windows 2000 when trying to run mythfrontend in there... perhaps it's the virtual video driver not having enough real video features to display -- Richard Dale

Solution: You need a 'real' (as in not VMWare/Virtual PC) hardware videocard with full DirectX 9 support to use Direct3D video output.

Vista 64 compatibility during compile

There seems to be some serious GCC/MSYS/MinGW Vista 64 bit edition compatibility issues with respect to most of the initial steps failing under Vista 64. Could anyone trying out this environment please post how they were able to workaround each step to achieve compile?

0.21-fixes crashes at startup

If mysql.txt cannot be found, 0.21-fixes frontend may crash due to a bug in UPnP. Create a mysql.txt and place it in your appdata directory. -- On WinXP: "%APPDATA%\.mythtv" -- On Vista: "%LOCALAPPDATA%\.mythtv"

0.21-fixes and pulseaudio

When running the latest 0.21-fixes, I was getting an error along the lines of 'pulseaudio is running but mythtv was not compiled with pulseaudio support. Exiting' when trying to start mythfrontend even though there is no way I was running pulseaudio on my windows machine. To fix this I edited the file "mythtv/libs/libmyth/util.cpp", then found the function:

bool IsPulseAudioRunning(void)

and added a return 0; to the start of the function, so it always thought pulseaudio wasn't running: