Successfully built HB with MinGW/MSYS (need help!)
Posted: Mon Feb 18, 2013 6:48 am
I'm planning to add Intel QuickSync supoort to HandBrake. Intel Media SDK is currently available for Windows only. So it'll be nice to be able to compile HandBrake using MinGW/MSYS under Windows.
I did some hacks, and built it successfully. I am not too familiar with the configuration and building scripts, so I don't know how to properly modify the source code of HB and generate a patch. I'll describe the dirty hacks below, hoping someone can help with it.
1. I only built 64-bit version. But I think 32-bit version might work as well.
2. I use msys(w/ git,svn,wget) from here: http://sourceforge.net/projects/mingwbu ... -packages/
mingw-w64: http://sourceforge.net/projects/mingw-w ... z/download
Note: I'm builing 64-bit HB under 64-bit Windows. But MSYS is 32-bit only thus the config.guess script will detect the host as i686-pc-mingw32. There might be other workarounds, but I use a simple one here: just use a 32-bit mingw which support cross-compiling to win64 target.
3. make/configure.py need some changes due to the MinGW/MSYS environment:
line 387: Should remove conftest.exe instead of conftest under Windows.
line 411: Change '%s/config.guess' to 'sh %s/config.guess' since the script isn't an executable and can't be invoked by python directly.
line 1356~1377: The script won't find ar, cp, gcc, etc. under Windows, it must look for ar.exe, cp.exe, gcc.exe, etc. instead. So we must add *.exe to the names argument. For example, change ToolProbe( 'AR.exe', 'ar' ) to ToolProbe( 'AR.exe', 'ar', 'ar.exe' ).
After the above changes, you can successfully configure HB.
4. build/GNUmakefile need to change due to the backslash(\) in paths:
Just replace all backslashes(\) in this file with slashes(/).
Cause: Python os module will generate \ instead of / in paths under Windows because it's a Windows convention. Backslash in makefiles will not be a problem itself, but in this one there're variables like SRC/, BUILD/, etc. of which the define lines will end with backslashes. Backslash will be treated as a line-continuation character in this case, thus mess up these varibale value. In fact, Windows has no problem recognizing slashes(/) in paths, and even support mix use of / and \. So simply changing all backslashes or only the ones which is the last character of a line, to slashes, will do the trick.
A more elegant solution is modifying configure.py so that it will use slash instead of backslash in paths even under Windows.
Now, cd to build/ and type make to build HB.
5. 'cc not found' when compiling yasm
I examed build/contrib/yasm/yasm-1.2.0/Makefile and found that CC is properly set to (in my case) C:/dev/msys/mingw/bin/x86_64-w64-mingw32-GCC.exe -std=gnu99, but CCLD_FOR_BUILD and CC_FOR_BUILD is set to cc, which is obviously incorrect, especially considering I was cross-compiling.
I don't know why these two variables are not set correctly, I just change Makefile to get compiling continue.
Type make to continue building.
6. 'more than one -exported-symbols argument is not allowed' when linking fribidi
Edit build/contrib/fribidi/fribidi-0.19.2/lib/Makefile.am: remove -export-symbols-regex "^fribidi_.*" from libfribidi_la_LDFLAGS
Type make to continue building.
7. 'libmp4v2.a(mp4.o): undefined reference' when linking hb.dll and HandBrakeCLI.exe
These references are all in libstdc++. Becuase libmp4v2 is written in c++, and the building script use gcc wrapper to link hd.dll and HandBrakeCLI.exe, the option -lstdc++ is not implied. So we must explicitly add -lstdc++ or change to g++ wrapper.
These are what I did:
libhb/module.defs, insert before line 99: LIBHB.GCC.l += stdc++
test/module.defs, insert before line 36: TEST.GCC.l += stdc++
You can make these changes before building. Type make to continue building.
After all these hacks, you can successfully built HB. You'll find HandBrakeCLI.exe under build/ and hb.dll under build/libhb/.
Open win/CS/HandBrake10.sln using Visual Studio, change the configuration to Release|x64 (in my case), and build solution. Copy build/HandBrakeCLI.exe and build/libhb/hb.dll to win/CS/HandBrakeWPF/bin/ and all work is done.
The thing is I don't know how to get all the workarounds above into HandBrake source tree so that it won't need manual hacking everytime you compile and won't break compiling under other platforms. So anyone can help with this?
I did some hacks, and built it successfully. I am not too familiar with the configuration and building scripts, so I don't know how to properly modify the source code of HB and generate a patch. I'll describe the dirty hacks below, hoping someone can help with it.
1. I only built 64-bit version. But I think 32-bit version might work as well.
2. I use msys(w/ git,svn,wget) from here: http://sourceforge.net/projects/mingwbu ... -packages/
mingw-w64: http://sourceforge.net/projects/mingw-w ... z/download
Note: I'm builing 64-bit HB under 64-bit Windows. But MSYS is 32-bit only thus the config.guess script will detect the host as i686-pc-mingw32. There might be other workarounds, but I use a simple one here: just use a 32-bit mingw which support cross-compiling to win64 target.
3. make/configure.py need some changes due to the MinGW/MSYS environment:
line 387: Should remove conftest.exe instead of conftest under Windows.
line 411: Change '%s/config.guess' to 'sh %s/config.guess' since the script isn't an executable and can't be invoked by python directly.
line 1356~1377: The script won't find ar, cp, gcc, etc. under Windows, it must look for ar.exe, cp.exe, gcc.exe, etc. instead. So we must add *.exe to the names argument. For example, change ToolProbe( 'AR.exe', 'ar' ) to ToolProbe( 'AR.exe', 'ar', 'ar.exe' ).
After the above changes, you can successfully configure HB.
4. build/GNUmakefile need to change due to the backslash(\) in paths:
Just replace all backslashes(\) in this file with slashes(/).
Cause: Python os module will generate \ instead of / in paths under Windows because it's a Windows convention. Backslash in makefiles will not be a problem itself, but in this one there're variables like SRC/, BUILD/, etc. of which the define lines will end with backslashes. Backslash will be treated as a line-continuation character in this case, thus mess up these varibale value. In fact, Windows has no problem recognizing slashes(/) in paths, and even support mix use of / and \. So simply changing all backslashes or only the ones which is the last character of a line, to slashes, will do the trick.
A more elegant solution is modifying configure.py so that it will use slash instead of backslash in paths even under Windows.
Now, cd to build/ and type make to build HB.
5. 'cc not found' when compiling yasm
I examed build/contrib/yasm/yasm-1.2.0/Makefile and found that CC is properly set to (in my case) C:/dev/msys/mingw/bin/x86_64-w64-mingw32-GCC.exe -std=gnu99, but CCLD_FOR_BUILD and CC_FOR_BUILD is set to cc, which is obviously incorrect, especially considering I was cross-compiling.
I don't know why these two variables are not set correctly, I just change Makefile to get compiling continue.
Type make to continue building.
6. 'more than one -exported-symbols argument is not allowed' when linking fribidi
Edit build/contrib/fribidi/fribidi-0.19.2/lib/Makefile.am: remove -export-symbols-regex "^fribidi_.*" from libfribidi_la_LDFLAGS
Type make to continue building.
7. 'libmp4v2.a(mp4.o): undefined reference' when linking hb.dll and HandBrakeCLI.exe
These references are all in libstdc++. Becuase libmp4v2 is written in c++, and the building script use gcc wrapper to link hd.dll and HandBrakeCLI.exe, the option -lstdc++ is not implied. So we must explicitly add -lstdc++ or change to g++ wrapper.
These are what I did:
libhb/module.defs, insert before line 99: LIBHB.GCC.l += stdc++
test/module.defs, insert before line 36: TEST.GCC.l += stdc++
You can make these changes before building. Type make to continue building.
After all these hacks, you can successfully built HB. You'll find HandBrakeCLI.exe under build/ and hb.dll under build/libhb/.
Open win/CS/HandBrake10.sln using Visual Studio, change the configuration to Release|x64 (in my case), and build solution. Copy build/HandBrakeCLI.exe and build/libhb/hb.dll to win/CS/HandBrakeWPF/bin/ and all work is done.
The thing is I don't know how to get all the workarounds above into HandBrake source tree so that it won't need manual hacking everytime you compile and won't break compiling under other platforms. So anyone can help with this?