VirtualBox 4.3.6 编译 for 64bit Windows

废话少说进入正题.

话说 VirtualBox 的Build 教程 估计想编的人都看过 但我估计编译成功的人不多.

这个是官方文档 https://www.virtualbox.org/wiki/Windows%20build%20instructions 也是需要看下的

准备官方要求的各种 64位库 

首先就是下代码了… 以 最新的 VirtualBOx 4.3.6 为例吧

VirtualBox 4.3.6  找个目录解开

你解包的代码编码是有问题的需要转换下

先弄2个bat 文件

conv.bat

set path=%path%;"D:\Build64\libiconv\bin\"
for /f "delims=" %%i in ('dir /b /a-d /s *.cpp *.h') do a2u %%i

a2u.bat

for %%f in (%1) do copy %%f %%f.ascII
for %%f in (%1) do iconv -c -f ascii -t utf-8 %%f.ascII > %%f


保存到源代码根目录

这个 “D:\Build\libiconv\bin\”   是iconv 工具你要改到相应目录下 

执行conv.bat     他会生成utf-8的代码

然后执行下 del *.ascII /s 删除垃圾          ps 这转换命令只能执行一次啊啊啊啊啊啊啊啊!!  有时会失败 把文件变成0字节…    失败了就解压重来一次么 ^ ^

这样你的代码编码 就转换了.

下来就是 把官方要求的 各种库 工具都装齐   有个顺序   先vs2010   再wdk 然后 vs2010sp1 要不然有个什么玩意冲突 麻烦!

windows sdk 可以不装 就用 vs自带的就行.

再来修改 configure.vbs  中文的那段

if (strPathVCCommon <> "") Then
      EnvAppend "PATH", ";" & strPathVCCommon & "/IDE"
   end if
   if Shell(DosSlashes(strPathVC & "/cl.exe"), True) <> 0 then
      MsgError "Executing '" & strClExe & "' (which we believe to be the Visual C++ compiler driver) failed."
      exit sub
   end if

   if   (InStr(1, g_strShellOutput, "编译器 16.") <= 0) _
    And (InStr(1, g_strShellOutput, "17.00") <= 0) then
      MsgError "The Visual C++ compiler we found ('" & strPathVC & "') isn't 10.0 or 11.0. Check the build requirements."
      exit sub
   end if

   '
   ' Ok, emit build config variables.
   '
   if InStr(1, g_strShellOutput, "编译器 16.") > 0 then
      CfgPrint "PATH_TOOL_VCC100      := " & g_strPathVCC
      CfgPrint "PATH_TOOL_VCC100X86   := $(PATH_TOOL_VCC100)"
      CfgPrint "PATH_TOOL_VCC100AMD64 := $(PATH_TOOL_VCC100)"
      if LogFileExists(strPathVC, "atlmfc/include/atlbase.h") then
         PrintResult "Visual C++ v10 with ATL", g_strPathVCC
      elseif   LogFileExists(g_strPathDDK, "inc/atl71/atlbase.h")

我自己写了个跑configure.vbs脚本的bat 也贴上来吧

run.bat

set PATH=%PATH%;D:\build64\MinGW64\bin;D:\Python27

cscript configure.vbs --with-MinGW32="D:\build64\MinGW64\bin\" ^
--with-libSDL="D:\build64\SDL" ^
--with-openssl="D:\build64\OpenSSL" ^
--with-libcurl="D:\build64\libcurl" ^
--with-Qt4="D:\build64\Qt4" ^
--with-MinGW-w64="D:\build64\MinGW64\bin\" ^
--with-python="D:\Python27"

通过以上也可以看出我build时 使用的目录结构

打开 vs x64命令行 !!!!!! 别用cmd!!!!!

run 一下 生成一个 AutoConfig.kmk    其实罗嗦一大堆脚本 这个 AutoConfig.kmk 才是真正用到的

贴一下我的

# -*- Makefile -*-
#
# Build configuration generated by cscript configure.vbs --with-MinGW32=D:\build64\MinGW64\bin\ --with-libSDL=D:\build64\SDL --with-openssl=D:\build64\OpenSSL --with-libcurl=D:\build64\libcurl --with-Qt4=D:\build64\Qt4 --with-MinGW-w64=D:\build64\MinGW64\bin\ --with-python=D:\Python27
#
VBOX_OSE := 1
PATH_SDK_WINDDK71     := D:/WinDDK/7600.16385.1
VBOX_WITH_WDDM_W8     := 
PATH_TOOL_VCC100      := C:/PROGRA~2/MICROS~2.0/VC
PATH_TOOL_VCC100X86   := $(PATH_TOOL_VCC100)
PATH_TOOL_VCC100AMD64 := $(PATH_TOOL_VCC100)
VBOX_WITHOUT_COMPILER_REDIST=1
PATH_TOOL_VCC100_ATLMFC_INC       = D:/WinDDK/7600.16385.1/inc/atl71
PATH_TOOL_VCC100_ATLMFC_LIB.amd64 = D:/WinDDK/7600.16385.1/lib/ATL/amd64
PATH_TOOL_VCC100_ATLMFC_LIB.x86   = D:/WinDDK/7600.16385.1/lib/ATL/i386
PATH_TOOL_VCC100AMD64_ATLMFC_INC  = D:/WinDDK/7600.16385.1/inc/atl71
PATH_TOOL_VCC100AMD64_ATLMFC_LIB  = D:/WinDDK/7600.16385.1/lib/ATL/amd64
PATH_TOOL_VCC100X86_ATLMFC_INC    = D:/WinDDK/7600.16385.1/inc/atl71
PATH_TOOL_VCC100X86_ATLMFC_LIB    = D:/WinDDK/7600.16385.1/lib/ATL/i386
PATH_SDK_WINPSDK71    := C:/PROGRA~2/MICROS~3/Windows/v7.0A
VBOX_WINPSDK          := WINPSDK71
VBOX_MAIN_IDL         := C:/PROGRA~2/MICROS~3/Windows/v7.0A/bin/Midl.exe
PATH_TOOL_MINGWW64    := D:/build64/MinGW64
VBOX_WITH_OPEN_WATCOM := 
PATH_SDK_LIBSDL       := D:/build64/SDL
SDK_VBOX_OPENSSL_INCS := D:/build64/OpenSSL/include
SDK_VBOX_OPENSSL_LIBS := D:/build64/OpenSSL/lib/ssleay32.lib D:/build64/OpenSSL/lib/libeay32.lib
SDK_VBOX_BLD_OPENSSL_LIBS := D:/build64/OpenSSL/lib/ssleay32.lib D:/build64/OpenSSL/lib/libeay32.lib
SDK_VBOX_LIBCURL_INCS := D:/build64/libcurl/include
SDK_VBOX_LIBCURL_LIBS := D:/build64/libcurl/libcurl.lib
PATH_SDK_QT4          := D:/build64/Qt4
PATH_TOOL_QT4         := $(PATH_SDK_QT4)
VBOX_PATH_QT4         := $(PATH_SDK_QT4)
VBOX_BLD_PYTHON       := D:\Python27\python.exe


这里

PATH_TOOL_VCC100      := C:/PROGRA~2/MICROS~2.0/VC/bin

改成

PATH_TOOL_VCC100 := C:/PROGRA~2/MICROS~2.0/VC

他这个vbs脚本从一诞生就没怎么正常过 反正都要改  这里用的短路径 “~2” 你我可能不同

4.3 的 代码里多了个  VBOX_WITH_32_ON_64_MAIN_API 宏    注意凡是 -x86 后缀的文件名 都是32位的 link 的时候需要 32位的lib库  

我嫌麻烦直接在 config.kmk里关掉了这个宏

line 517  

#VBOX_WITH_32_ON_64_MAIN_API = 1

还有漏的比如这个 

把 代码路径src\VBox\Runtime\Makefile.kmk  这段 删除

#
# VBoxRT-x86 - 32-bit version of VBoxRT
#
VBoxRT-x86_EXTENDS = VBoxRT
VBoxRT-x86_TEMPLATE = VBoxR3Dll-x86
VBoxRT-x86_SDKS  = VBOX_LIBXML2
ifdef VBOX_WITH_LIBCURL
 VBoxRT-x86_SDKS += VBOX_LIBCURL-x86
endif
VBoxRT-x86_SDKS  += VBOX_OPENSSL-x86

VBoxRT-x86_LIBS = \
	$(PATH_STAGE_LIB)/VBox-liblzf-x86$(VBOX_SUFF_LIB)
if1of ($(KBUILD_TARGET_ARCH), amd64 x86)
VBoxRT-x86_LIBS += \
	$(PATH_STAGE_LIB)/SUPR3-x86$(VBOX_SUFF_LIB)
endif
ifdef IPRT_WITH_KSTUFF
 VBoxRT-x86_LIBS                  += \
	$(PATH_STAGE_LIB)/VBox-kStuff-x86$(VBOX_SUFF_LIB)
endif
ifndef SDK_VBOX_LIBXML2_LIBS
 VBoxRT-x86_LIBS                 += \
	$(PATH_STAGE_LIB)/VBox-libxml2-x86$(VBOX_SUFF_LIB)
endif
VBoxRT-x86_LIBS                  += \
	$(SDK_VBOX_ZLIB_LIBS-x86)
ifndef SDK_VBOX_OPENSSL_LIBS
 VBoxRT-x86_LIBS                 += \
	$(PATH_STAGE_LIB)/VBox-libcrypto-x86$(VBOX_SUFF_LIB) \
	$(PATH_STAGE_LIB)/VBox-libssl-x86$(VBOX_SUFF_LIB)
endif
ifdef IPRT_WITH_LZO
 VBoxRT-x86_LIBS                  += lzo2
endif
VBoxRT-x86_LIBS.linux              = \
	crypt
VBoxRT-x86_LIBS.darwin             = \
	iconv
VBoxRT-x86_LIBS.freebsd            = \
	iconv \
	rt
VBoxRT-x86_LIBS.haiku              = \
	iconv
VBoxRT-x86_LIBS.solaris            = \
	kstat \
	contract
ifn1of ($(KBUILD_TARGET_ARCH), sparc32 sparc64)
 # SMBIOS not available on Solaris SPARC.
 VBoxRT-x86_LIBS.solaris += smbios
endif
VBoxRT-x86_LIBS.win                = \
	$(PATH_SDK_$(VBOX_WINDDK)_LIB.x86)/vccomsup.lib \
	$(PATH_SDK_$(VBOX_WINDDK)_LIB.x86)/wbemuuid.lib

VBoxRT-x86_SOURCES.win = $(filter-out %.def,$(VBoxRT_SOURCES.win)) \
	$(VBoxRT-x86_0_OUTDIR)/VBoxRT-x86.def
if1of ($(DLLS), VBoxRT-x86)
$$(VBoxRT-x86_0_OUTDIR)/VBoxRT-x86.def: \
		$(PATH_SUB_CURRENT)/r3/win/VBoxRT-win32.def \
		$(PATH_SUB_CURRENT)/r3/win/$(if $(VBOX_OSE),VBoxRT-openssl-ose.def,VBoxRT-openssl.def)
	$(RM) -f -- $@
	$(REDIRECT) -wto $@ -- $(CAT_EXT) $^
endif


还有个testcase会出错 说找不到 /bin/nm.exe连目录直接删掉好了 或者注掉

src\VBox\VMM\testcase\Makefile.kmk

line 372

ifeq ($(KBUILD_HOST),win)
# ifndef TOOL_MINGW32
#  include $(KBUILD_PATH)/tools/MINGW32.kmk
# endif
# VBOX_NM ?= $(PATH_TOOL_MINGW32)/bin/nm.exe -p
#else
 VBOX_NM ?= nm -p
endif

因该是PATH 环境变量的问题 要把你mingw64\bin 放进去

按照官方的驱动测试模式 操作下

Only for 64 bit builds: setting up self signing
Part 1: creating and installing the test certificate

Launch an elevated command line shell (Vista and later).
makecert.exe -r -pe -ss my -n "CN=MyTestCertificate" mytestcert.cer
certmgr.exe -add mytestcert.cer -s -r localMachine root
Start certmgr.exe and check that "MyTestCertificate" is listed both under "Personal" and "Trusted Root Certification Authorities".
Keep the mytestcert.cer file in a safe place.
Part 2: configuring the system to run test signed code (Vista and later)

Launch an elevated command line shell (Vista and later).
Run Bcdedit.exe -set TESTSIGNING ON on an elevated cmd.exe prompt.
certmgr.exe -add mytestcert.cer -s -r localMachine root
certmgr.exe -add mytestcert.cer -s -r localMachine trustedpublisher
Reboot.
Vista: "Test Mode" will appear in all four corners of the desktop and "Microsoft (R) Windows (R) (Build 6000)" will appear on the top. Windows 7: "Test ModeWindows 7Build 7600" will appear in the lower right corner.
Part 3: building VirtualBox with signing enabled

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.
Add VBOX_SIGNING_MODE=test to LocalConfig.kmk.
Build (incremental is sufficient).

注册下环境变量

set LIB_TARGET=amd64
set VBOX_PATH_SELFSIGN=D:/WinDDK/7600.16385.1/bin/selfsign
set VBOX_SIGNTOOL="D:/WinDDK/7600.16385.1/bin/amd64/SignTool.exe"
set VBOX_CROSS_CERTIFICATE_FILE=D:/build64/VirtualBox/mytestcert.cer
set VBOX_INF2CAT="D:/WinDDK/7600.16385.1/bin/selfsign/Inf2Cat.exe"
call kbuild\envwin.sh -release -win64
call env.bat

kmk 喽

正常情况就编完了 断了就改改代码喽…

有什么问题我以后再补充