Building VirtualBox OSE 5.0.0 on Windows 7 (x86)

Discussions related to using the OSE version of VirtualBox.
Post Reply
NTI
Posts: 21
Joined: 23. Jul 2015, 12:35

Building VirtualBox OSE 5.0.0 on Windows 7 (x86)

Post by NTI »

I have successfully built and test signed VirtualBox OSE 5.0.0 on Windows 7 (x86) thanks for the information from this forum. I'd like to share my experience here.

1. Build environment: Windows 7 x86
2. Prerequisites for downloading
To be installed in the following recommended order:
2.1 Visual Studio 2010 Pro
2.2 Windows Platform SDK v7.1
http://www.microsoft.com/en-us/download ... px?id=8279
2.3 Install Visual Studio 2010 Service Pack 1
2.4 Install Visual C++ 2010 SP1 Compiler Update for Windows SDK 7.1
http://www.microsoft.com/en-us/download ... px?id=4422
2.5 Windows Driver Development Kit (WDK) v7.1
http://www.microsoft.com/en-us/download ... n&id=11800
2.6 Python 2.7 (a version newer than 2.7 might cause building errors)
2.7 ActivePerl 5.20
2.8 MingW (32-bit Windows only):
GCC 3.3.3: http://prdownloads.sf.net/mingw/gcc-cor ... z?download
and http://prdownloads.sf.net/mingw/gcc-g++ ... z?download
Runtime: http://prdownloads.sf.net/mingw/mingw-r ... z?download
W32API: http://prdownloads.sf.net/mingw/w32api- ... z?download
Binutils 2.19: http://sourceforge.net/projects/mingw/f ... tils-2.19/
Note: All the packages need to be extracted and merged to the same root folder (e.g., C:\VBox\MinGW32-3.3.3\bin, C:\VBox\MinGW32-3.3.3\include, C:\VBox\MinGW32-3.3.3\lib)
Set C:\VBox\MinGW32-3.3.3\bin in PATH
2.9 SDL v1.2.15 or later development package http://www.libsdl.org/download-1.2.php

3. Prerequisites for building
3.1 Build QT 4.7.x or later
1)Download Qt-4.7.3 source code (qt-everywhere-opensource-src-4.7.3.tar.gz) from https://download.qt.io/archive/qt/4.7/ and extract to ..\qt-4.7.3
2)Download jom from https://wiki.qt.io/Jom and extract to ..\VBox\jom ("jom" is a clone of nmake to support the execution of multiple independent commands in parallel.)
3)Update the PATH variable to include ..\qt-4.7.3\bin
4)Open a VS2010 command prompt (Start > Programs > Microsoft Visual Studio 2010 > Visual Studio Tools > Visual Studio Command Prompt)
5)Go to the source code directory of qt 4.7.3 (..\qt-4.7.3\)
6)Set QMAKESPEC to the corresponding VS version

Code: Select all

e.g., set QMAKESPEC=C:\VBox\qt-4.7.3\mkspecs\win32-msvc2010
7) Run configure command:

Code: Select all

configure -debug-and-release -opensource -platform win32-msvc2010
8.) Run build commands:

Code: Select all

Option 1: using jom – 
C:\dev\VBox\qt-4.7.3>..\jom\jom.exe -j N
(Where N is number of CPU cores you want to utilize for Qt compilation. Larger is better.

Option 2: using nmake – 
C:\dev\VBox\qt-4.7.3>nmake
3.2 Build Openssl 1.0.1 or later
1) Download source code from http://olex.openlogic.com/packages/open ... etail_tabs (Note: The header files under “..\openssl-xxx\include\openssl” always have 0 size when the package is downloaded. They are populated with links during the make phase.)
2) Open a VS2010 command prompt
3) Build Openssl
i. Install ActivePerl (e.g., at C:\Perl)
ii. Update the PATH variable to include ..\Perl\bin
iii. For 32-bit build: go to the OpenSSL source folder for (e.g. cd C:\VBox\openssl-1.0.1p\) to run configure commands:

Code: Select all

perl Configure VC-WIN32 --prefix=C:\VBox\openssl-1.0.1p\output
ms\do_ms
nmake -f ms\ntdll.mak 
nmake -f ms\ntdll.mak install
Note: The build outputs will be in C:\VBox\openssl-1.0.1p\output

3.3 Build cURL
1) Download source code from http://curl.haxx.se/download.html
2) Open a VS2010 command prompt
3) Go to the directory of the source code (e.g., C:\VBox\curl-7.35.0) and set OPENSSL_PATH to the openssl directory (e.g., set OPENSSL_PATH=..\..\openssl-xxx)
4) Build commands:

Code: Select all

pushd lib
nmake /f Makefile.vc10 cfg=release-dll
Note: vc10 for Visual Studio 2010. The build outputs will be in ..\lib\release-dll
What VBox requires from cURL build output are
..\curl-7.35.0\include
..\ curl-7.35.0\lib\release-dll\libcurl.dll
..\ curl-7.35.0\lib\release-dll\libcurl_imp.lib (rename libcurl_imp.lib to libcurl.lib)

4 Build VirtualBox
4.1 Get source code of VBox (e.g., 5.0.0) from http://download.virtualbox.org/virtualb ... .0.tar.bz2 and extract to a folder (e.g., C:\VBox\VirtualBox-5.0.0)
4.2 Install Python and ActivePerl if they are not present
4.3 Open a VS2010 command prompt
4.4 Configure required libraries for VBox building:

Code: Select all

C:\VBox\VirtualBox-5.0.0>cscript configure.vbs --with-libSDL=C:\VBox\SDL-1.2.15 --with-openssl=C:\VBox\openssl-1.0.1p\output --with-libcurl=C:\VBox\curl-7.35.0 --with-QT4=C:\VBox\qt-4.7.3 --with-MinGW32=C:\VBox\MinGW32-3.3.3
Note: VBox complains if the version of MinGW is too new. Version 3.3.3 works.
If the configure command doesn’t succeed, please check “..\VirtualBox-5.0.0\configure.log” for errors.
If the script finds all the tools necessary, it will output two files: AutoConfig.kmk containing information where to find the tools on your system and env.bat, a batch file to setup your environment for building VirtualBox. You only have to execute this step once, unless something about your tools changes in which case you have to repeat the above step. Keep in mind that the script always overwrites the two generated files so you should not manually edit them.

4.5 To build an unhardening version of VBox, add the following in “..\VirtualBox-5.0.0\LocalConfig.kmk” (If LocalConfig.kmk doesn’t exit, create one).

Code: Select all

VBOX_WITH_HARDENING :=    

4.6 Add the following in “..\VirtualBox-5.0.0\Makefile.kmk”

Code: Select all

VBOX_BLD_PYTHON=C:\Python27\python.exe
4.7 Build VBox

Code: Select all

env.bat
kmk
kmk KBUILD_TYPE=debug (for debug version)
5 Install VirtualBox
Once VirtualBox is built successfully, there are a few steps to do before executing VirtualBox.exe:

5.1 Copy the following libraries to the same directory of VirtualBox.exe (e.g., C:\VBox\VirtualBox-5.0.0\out\win.x86\release\bin) or..\system32:

Code: Select all

libcurl.dll (e.g.,  from C:\VBox\curl-7.35.0\lib)
libeay32.dll (e.g., from C:\VBox\openssl-1.0.1p\output\bin)
ssleay32.dll (e.g., from C:\VBox\openssl-1.0.1p\output\bin)
QtCore4.dll (e.g., from C:\VBox\qt-4.7.3\bin)
QtGui4.dll (e.g., from C:\VBox\qt-4.7.3\bin)
QtNetwork4.dll (e.g., from C:\VBox\qt-4.7.3\bin)
QtOpenGL4.dll (e.g., from C:\VBox\qt-4.7.3\bin)
5.2 Open an elevated VS2010 command prompt and go to the same directory as VirtualBox.exe to run the following commands:

Code: Select all

comregister.cmd
loadall.cmd
Note: env.bat under ..\ VirtualBox-5.0.0\ needs to be run before loadall.cmd if it’s not been run under the current command session.

5.3 Run VirtualBox.exe to load VirtualBox

6 Signing VBox
To create a signed version of VBox, steps in Section 3-5 need to be modified as follows:
6.1 creating and installing the test certificate
6.1.1 Launch an elevated command line shell
6.1.2 makecert.exe -r -pe -ss my -n "CN=MyTestCertificate" mytestcert.cer
6.1.3 certmgr.exe -add mytestcert.cer -s -r localMachine root
6.1.4 Start certmgr.exe and check that "MyTestCertificate" is listed both under "Personal" and "Trusted Root Certification Authorities".
6.1.5 Keep the mytestcert.cer file in a safe place

6.2 Configuring the system to run test signed code
6.2.1 Launch an elevated command line shell
6.2.2 Run the following on an elevated cmd.exe prompt

Code: Select all

Bcdedit.exe -set TESTSIGNING ON
6.2.3 Run

Code: Select all

certmgr.exe -add mytestcert.cer -s -r localMachine root
certmgr.exe -add mytestcert.cer -s -r localMachine trustedpublisher
6.2.4 Reboot
6.2.5 Windows 7: "Test Mode<CR>Windows 7<CR>Build 7601" will appear in the lower right corner

6.3 Building prerequisite dlls for VBox
6.3.1 In order to be loaded by signed VBox, the prerequisite dlls should get a link option “Integrity Check” set in the dll headers. Edit the following configure files before building the prerequisites in Setion 3 to get the right link headers.
in ..\qt-4.7.3\mkspecs\win32-msvc2010\qmake.conf, edited the value of flag QMAKE_LFLAGS_DLL to

Code: Select all

"QMAKE_LFLAGS_DLL = /DLL /INTEGRITYCHECK"
in ..\openssl-1.0.1p\ms\ntdll.mak, change to the following

Code: Select all

"LFLAGS=/nologo /subsystem:console /opt:ref /debug /INTEGRITYCHECK" 
"MLFLAGS= /nologo /subsystem:console /opt:ref /debug /dll /INTEGRITYCHECK"  
note: ntdll.mak got over written after command "ms\do_ms". Pls do the changes after the command.

In ..\curl-7.35.0-src\curl-7.35.0\lib\Makefile.vc10, change to the following

Code: Select all

"LNKDLL = link.exe /DLL /INTEGRITYCHECK"
6.3.2 Follow the build instruction in Section 3 to build the prerequisites.

6.3.3 Sign the built dlls using command

Code: Select all

Signtool.exe sign –v [name].dll
Sign the following:

Code: Select all

libcurl.dll (e.g.,  from C:\VBox\curl-7.35.0\lib)
libeay32.dll (e.g., from C:\VBox\openssl-1.0.1p\output\bin)
ssleay32.dll (e.g., from C:\VBox\openssl-1.0.1p\output\bin)
QtCore4.dll (e.g., from C:\VBox\qt-4.7.3\bin)
QtGui4.dll (e.g., from C:\VBox\qt-4.7.3\bin)
QtNetwork4.dll (e.g., from C:\VBox\qt-4.7.3\bin)
QtOpenGL4.dll (e.g., from C:\VBox\qt-4.7.3\bin)
6.3.4 Run the following command to check the Integrity Check flag has been set in dll headers:

Code: Select all

Link.exe /dump /headers [name].dll
Check under “DLL characteristics”, it should have “Check integrity” present.

6.3.5 Copy and paste the above signed dlls to the same directory of VirtualBox.exe

6.4 Building VirtualBox with signing enabled
6.4.1 If you called the certificate something other than MyTestCertificate you'll have make the appropriate overrides in LocalConfig.kmk. See the Code Signing section of Config.kmk for what can be overridden
6.4.2 Remove the following from LocalConfig.kmk

Code: Select all

VBOX_WITH_HARDENING :=  
6.4.3 Add the following to LocalConfig.kmk

Code: Select all

VBOX_SIGNING_MODE=test
6.4.4 Copy Signtool.exe (e.g. from C:\WinDDK\7600.16385.1\bin\x86) and Inf2Cat.exe (e.g. from C:\WinDDK\7600.16385.1\bin\selfsign) to ..\VBox\tools\win.x86\selfsign\r1
6.4.5 Build VBox (incremental is sufficient) – refer to Section 4
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Building VirtualBox OSE 5.0.0 on Windows 7 (x86)

Post by noteirak »

Thanks for the very detailed post! Lots of work in here... I'm going to make this a sticky.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
vthakkar
Posts: 14
Joined: 24. Nov 2015, 09:16

Re: Building VirtualBox OSE 5.0.0 on Windows 7 (x86)

Post by vthakkar »

Was your host environment 32 bit windows 7?

Have you tried building 32 bit VBOX on 64 bit Windows 7 host? For this, do you think we would need mingw32, or can I build it using mingw64 toolchain?
NTI
Posts: 21
Joined: 23. Jul 2015, 12:35

Re: Building VirtualBox OSE 5.0.0 on Windows 7 (x86)

Post by NTI »

vthakkar wrote:Was your host environment 32 bit windows 7?

Have you tried building 32 bit VBOX on 64 bit Windows 7 host? For this, do you think we would need mingw32, or can I build it using mingw64 toolchain?

Yes, the host machine was x86 Win7.

To build an x86 VBox on an x64 host, I think you still need mingw32 (but I've never tried). But be aware, you won't be able to load your built VBox (x86) on an x64 host machine. The kernel modules just won't load. If you are just building it and will load it from another x86 host machine, that's another story.
vthakkar
Posts: 14
Joined: 24. Nov 2015, 09:16

Re: Building VirtualBox OSE 5.0.0 on Windows 7 (x86)

Post by vthakkar »

Yeah, the target is to load it on x86 host only. But since most of our build machines are running x64 Windows host environment, we wanted to build 32 bit VBOX on x64 windows dev machine.
BTW, I did try with mingw32 and got errors with windres incompatibility (windres that comes with gcc 3.3.3 is apparently too old). The newer windres works but the build fails at a later stage.
nope
Posts: 2
Joined: 18. Jan 2016, 12:31

Re: Building VirtualBox OSE 5.0.0 on Windows 7 (x86)

Post by nope »

Hello,
I've followed the instruction and i'm still blocked on the compilation of virtualbox:

C:\Users\standard\Documents\virtualbox\5.0.12>kmk
Config.kmk:2568: C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/DynamicConfig.kmk: No such file or directory
Config.kmk:6187: C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/revision.kmk: No such file or directory
Makefile.kmk:29: C:/Users/standard/Documents/virtualbox/5.0.12/doc/manual/Makefile.kmk: No such file or directory
C:/Users/standard/Documents/virtualbox/5.0.12/src/VBox/Main/webservice/Makefile.kmk:105: VBOX_PATH_GSOAP not found...
kmk: *** No rule to make target `C:/Users/standard/Documents/virtualbox/5.0.12/doc/manual/Makefile.kmk'. Stop.

What should I do from their ?

Thanks,


EDIT: Well, I have downgraded my source code to 5.0.0, it compiles now.
nope
Posts: 2
Joined: 18. Jan 2016, 12:31

Re: Building VirtualBox OSE 5.0.0 on Windows 7 (x86)

Post by nope »

Hello,
I have some difficulties building VBoxREM32.dll for 5.0.0 and 5.0.12.
I succeeded in getting all the antiquated building tools, so I suppose I am in a relatively good building environnement.
Can you help me find a way to build this library ?

Thanks

kBuild: Generating C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxREMImp/VBoxREMRes.o
kBuild: Linking VBoxRemPrimary
C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxREMImp/VBoxREMRes.o: file not recognized: File format not recognized
C:/Users/standard/Documents/virtualbox-lib/MinGW/bin/dllwrap.exe: C:/Users/standard/Documents/virtualbox-lib/MinGW/bin/gcc.exe exited with status 1
kmk: *** [C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPrimary/VBoxREM32.dll] Error 1
The failing command:
@C:/Users/standard/Documents/virtualbox-lib/MinGW/bin/dllwrap.exe -s --dllname=C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPrimary/VBoxREM32.d
ll --output-exp=C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPrimary/VBoxREM32.exp --output-lib=C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VB
oxRemPrimary/VBoxREM32.a --def C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxREMImp/VBoxREMWin.def C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/V
BoxRemPrimary/VBoxRecompiler.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPrimary/cpu-exec.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBo
xRemPrimary/exec.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPrimary/translate-all.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPri
mary/host-utils.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPrimary/cutils.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPrimary/tcg
-runtime.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPrimary/tcg/tcg.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPrimary/tcg/tcg-d
yngen.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPrimary/fpu/softfloat-native.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPrimary
/target-i386/op_helper.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxRemPrimary/target-i386/helper.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj
/VBoxRemPrimary/target-i386/translate.o C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/obj/VBoxREMImp/VBoxREMRes.o -LC:/Users/standard/Documents/virtualbox-lib/MinGW/lib C:/Users
/standard/Documents/virtualbox/5.0.12/out/win.x86/release/lib/VBoxVMM.lib C:/Users/standard/Documents/virtualbox/5.0.12/out/win.x86/release/lib/VBoxRT.lib
Post Reply