24 April, 2007

Compiling gcc 4.1.2 under mingw

I have as many others been annoyed by the message that ffmpeg compiled under current mingw displays when started. It says: "Compiler did not align stack variables. Libavcodec has been miscompiled and may be very slow or crash. This is not a bug in libavcodec, but in the compiler. Do not report crashes to FFmpeg developers."

Googling reveals that this has been fixed in gcc 4.2 which is not released yet so you'd have to compile it yourself from svn source. Now, there are instructions for compiling (experimental) 4.1 so for the sake of exercise I decided to try that. As it turns out, the error message is actually gone when ffmpeg (and all external libraries that I use) are compiled with this new version. Someone is bound to know why, but I haven't figured it out yet - IIRC I have read that the error is NOT supposed to disappear with 4.1.2. Well, what do I know. Anyway below are the steps that I followed, lifted from the mingw wiki and slightly modified:

  1. Download latest stable gcc tarball
  2. Install latest MSYS/Mingw according to the "FFmpeg on Windows" wiki. However, use the latest updates from the Mingw site
  3. Install the additional stuff mentioned in the mingw wiki
  4. Create two directories in the msys directory, one for the clean source (I called it gccsource) and one work directory where the actual compile happens
  5. Unpack the gcc tarball in the source directory
  6. cd to the work directory and run the following (prefix is where the new gcc should be installed):

    ../gccsource/configure --prefix=/gcc412 --includedir=/mingw/include --libdir=/mingw/lib --host=mingw32 --target=mingw32 --program-prefix="" --with-as=/mingw/bin/as.exe --with-ld=/mingw/bin/ld.exe --with-gcc --with-gnu-ld --with-gnu-as --enable-threads --disable-nls --enable-languages=c,c++ --disable-win32-registry --disable-shared --without-x --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug

    make CFLAGS="-O2 -fomit-frame-pointer" CXXFLAGS="-mthreads -fno-omit-frame-pointer -O2" LDFLAGS=-s bootstrap2

    make install

    PATH=/gcc412/bin:$PATH

    gcc -v (to check things worked)
When I followed the instructions verbatim I had errors indicating that gcc wasn't able to find certain paths during the process, which is one of the reasons it is important to keep all directories in the MSYS directory as various mingw specific patches have (obviously) not been applied. This means that gcc does not handle virtual paths like /c/.... In addition I had to add --includedir=/mingw/include --libdir=/mingw/lib to make sure include files and libraries were found.

Also, remember to modify PATH so the new version is used if you want. Don't replace the old mingw version of gcc in case you run into problems.

So there it is. With the new version I recompiled all external libraries and ffmpeg itself and have had no problems at all. Your mileage may vary. OTOH you might want to wait for mingw to release its patched gcc 4.2, which apparently should happen relatively soon after it is formally released.

No comments:

Post a Comment