參考文檔
- https://www.virtualbox.org/wiki/Windows%20build%20instructions
- https://www.cnblogs.com/findumars/p/5542973.html
機(jī)器環(huán)境及之前已有庫(kù)
- windows 10 x64
- Visual Studio 2015 Community 版本
- Windows Driver Development Kit (WDK) v7.1
- Qt5.7.1
- Python 2.7.8
- Nsis 3.0b1
- JDK7 JDK8
- zlib 在 D:\thridparty\zlib
- VirtualBox 69891版本
下載工具和庫(kù)
下載Virtualbox推薦的鏈接
-
mingw64下載解壓到
D:\projects\virtualbox\mingw64
mingw32
以下文件都解壓D:\projects\virtualbox\mingw32
- GCC 3.3.3
- GCC-g++ 3.3.3
- MinGW Runtime 此版本編譯報(bào)錯(cuò),應(yīng)該下載更新版本,如mingwrt-3.22.4眶诈。
- W32API
- Binutils财岔。此版本windres會(huì)報(bào)錯(cuò)敏弃,應(yīng)該下載更新版本循狰,如binutils-2.28
openssl
其實(shí)下Light版本應(yīng)該就夠了
- openssl 64 https://slproweb.com/download/Win64OpenSSL-1_1_0g.exe
- openssl 32 https://slproweb.com/download/Win32OpenSSL-1_1_0g.exe
其它庫(kù)
- libxml2 virtualbox已含
- zlib virtualbox已含
- 其它可選庫(kù)都不要
check out代碼
- 下載 https://github.com/svn2github/virtualbox.git 到 D:\projects\virtualbox,則D:\projects\virtualbox\trunk是virtualBox代碼目錄已艰。
- 在virtualBox代碼目錄中下載
http://svn.netlabs.org/repos/kbuild/trunk/kBuild - 下載curl代碼庫(kù) https://github.com/curl/curl.git 至D:\thridparty\curl榛做。VirtualBox推薦的下載地址http://curl.haxx.se/download.html中找不到windows版本的devel包唁盏,只好自己編譯,編譯步驟參考:http://blog.csdn.net/alger_magic/article/details/52584579
編譯curl
將以下指令保存到curl根目錄的批處理文件中瘤睹,并執(zhí)行:
build_dll.bat
@echo off
@cd winbuild
@echo 正在使用release模式編譯libcurl~~~
@nmake /f Makefile.vc WITH_DEVEL=D:\VC_INCLUDE\OpenSSL-Win32 WITH_ZLIB=D:\thridparty\zlib mode=dll VC=14 WITH_SSL=dll ENABLE_IDN=no RTLIBCFG=dll DEBUG=no MACHINE=x86
@REM @echo on
@cd ..
build_dll_x64.bat
@echo off
@cd winbuild
@echo 正在使用release模式編譯libcurl~~~
@nmake /f Makefile.vc WITH_DEVEL=D:\VC_INCLUDE\OpenSSL-Win64 WITH_ZLIB=D:\thridparty\zlib mode=dll VC=14 WITH_SSL=dll ENABLE_IDN=no RTLIBCFG=dll DEBUG=no MACHINE=x64
@REM @echo on
@cd ..
編譯輸出在
- D:\thridparty\curl\builds\libcurl-vc14-x64-release-dll-ssl-dll-ipv6-sspi
- D:\thridparty\curl\builds\libcurl-vc14-x86-release-dll-ssl-dll-ipv6-sspi
因?yàn)関irtualbox查找curl的lib和dll時(shí)只在指定目錄查找升敲,所以還需要將他們子目錄下的bin和lib目錄里的文件拷貝到父級(jí)目錄。
編譯Virtulbox
LocalConfig.kmk
代碼根目錄新建文件LocalConfig.kmk轰传,內(nèi)容:
VBOX_WITH_ADDITIONS=
VBOX_WITH_ADDITIONS_PACKING=
#Don't build + package the VirtualBox Guest Additions. If only VBOX_WITH_ADDITIONS= is specified then the Guest Additions are not built but the VBoxGuestAdditions.iso file is expected to be present in the 'out\win.ARCH\release\bin\additions' directory.
VBOX_ONLY_ADDITIONS=1
#Build the Guest Additions exclusively.
VBOX_WITH_VALIDATIONKIT=
#Don't build + package the VirtualBox validation kit. The validation kit is not part of the final .msi package anyway.
VBOX_WITH_WEBSERVICES=
#Don't build + package the webservices API server.
VBOX_WITHOUT_HARDENING=1
VBOX_INF2CAT=D:\WinDDK\7600.16385.1\bin\selfsign\Inf2Cat.exe
VBOX_PATH_SIGN_TOOLS=D:\WinDDK\7600.16385.1\bin\amd64\SignTool.exe
# 以下的我不用驴党,只是機(jī)器上有,就放上來(lái)
VBOX_PATH_NSIS=D:\Program Files\NSIS
VBOX_ZIP=D:\VC_INCLUDE\GetGnuWin32\gnuwin32\bin\zip.exe
VBOX_PATH_WISUMINFO=D:\projects\Microsoft SDKs\Windows\v7.1\Samples\sysmgmt\msi\scripts\WiSumInf.vbs
VBOX_MKISOFS=C:\Program Files (x86)\VMware\VMware Workstation\mkisofs.exe
configure.vbs
configure.vbs中修改代碼
if (InStr(1, g_strShellOutput, "Version 16.") <= 0) _
And (InStr(1, g_strShellOutput, "Version 17.") <= 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
為
if (InStr(1, g_strShellOutput, "Version 16.") <= 0) _
And (InStr(1, g_strShellOutput, "Version 17.") <= 0) _
And (InStr(1, g_strShellOutput, "Version 18.") <= 0) _
And (InStr(1, g_strShellOutput, "19.00") <= 0) then
MsgError "Check Version failed: The Visual C++ compiler we found ('" & strPathVC & "') isn't 10.0 - 14.0. Check the build requirements."
exit sub
end if
用來(lái)支持vs2015
build.bat
根目錄新建build_x64.bat:
@echo off
set cur_dir= %~dp0%
call D:\projects\virtualbox\kBuild\envwin.cmd
cscript %cur_dir%configure.vbs --with-vc="C:\Program Files (x86)\Microsoft Visual Studio 14.0" --with-MinGW-w64=D:\projects\virtualbox\mingw64 --with-SDK="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A" --with-DDK=D:\VC_INCLUDE\Windows\WinDDK --with-Qt5=E:\Qt\Qt5.7.1\5.7\msvc2015_64 --with-python=D:\Python27 --with-libcurl32=D:\thridparty\curl\builds\libcurl-vc14-x86-release-dll-ssl-dll-ipv6-sspi --with-libcurl=D:\thridparty\curl\builds\libcurl-vc14-x64-release-dll-ssl-dll-ipv6-sspi --with-openssl32="D:\VC_INCLUDE\OpenSSL-Win32" --with-openssl="D:\VC_INCLUDE\OpenSSL-Win32" --disable-SDL --target-arch=amd64
pause
執(zhí)行之获茬,然后再在命令行中分別執(zhí)行:
env
kmk
問(wèn)題
kmk: *** Invalid number "ev". Stop.
執(zhí)行kmk后港庄,出現(xiàn)這個(gè)問(wèn)題,然后我無(wú)論是切換virtualbox的版本還是切換kbuild的版本恕曲,最后安裝了vs2010版本鹏氧。結(jié)果還是報(bào)這個(gè)錯(cuò)誤。
最后挨個(gè)文件夾執(zhí)行kmk佩谣,最后發(fā)現(xiàn)在virtualbox\trunk\src\recompiler
中kmk提示這個(gè)錯(cuò)誤把还。
打開(kāi)這個(gè)目錄的Makefile.kmk后搜索ev,只搜索到DVBOX_SVN_REV
茸俭,就想起來(lái)既然makefile中使用到了svn版本號(hào)吊履,而我用的這個(gè)庫(kù)又是git的,那問(wèn)題會(huì)不會(huì)出現(xiàn)在svn版本號(hào)生成的地方调鬓。后面又在kmk輸出的out\revision.kmk里發(fā)現(xiàn)了export VBOX_SVN_REV=ev
這樣一來(lái)問(wèn)題就很明顯了艇炎。我只需要在生成svn版本號(hào)的地方改一下代碼即可,但是手改config.kmk中的svn版本號(hào)分析實(shí)在是太煩了腾窝,所以就直接在LocalConfig.kmk中添加一行VBOX_SVN_REV=69807
即可解決缀踪。
找不到 <k/kLdr.h>
在D:\projects\virtualbox\trunk\src\VBox\Runtime\common\ldr\ldrkStuff.cpp
中有#include <k/kLdr.h>
居砖,但是代碼庫(kù)里沒(méi)有。在老版本的文件列表里倒是能找到驴娃。
最后沒(méi)辦法奏候,先屏蔽掉它吧。在LocalConfig.kmk
中添加一行IPRT_WITH_KSTUFF=
這樣D:\projects\virtualbox\trunk\src\VBox\Runtime\Makefile.kmk
中就不會(huì)包含kdrkStuff.cpp
了托慨。
ifdef IPRT_WITH_KSTUFF
RuntimeR3_SOURCES += \
common/ldr/ldrkStuff.cpp
endif
后面發(fā)現(xiàn)鼻由,可以從http://www.virtualbox.org/svn/kstuff-mirror下載kstuff的源碼,所以這個(gè)又能編譯的過(guò)
spu_dispatch_table.h
D:\projects\virtualbox\trunk\src\VBox\GuestHost\OpenGL\include\cr_spu.h(16) : fatal error C1083: 無(wú)法打開(kāi)包括文件:“spu_dispatch_table.h”: No such file or directory
查看MakeFile發(fā)現(xiàn)D:\projects\virtualbox\trunk\src\VBox\Additions\common\crOpenGL\Makefile.kmk中用到D:\projects\virtualbox\trunk\src\VBox\GuestHost\OpenGL\Makefile.kmk中生成的spu_dispatch_table.h厚棵。而OpenGL\Makefile.kmk還沒(méi)有執(zhí)行蕉世。
并且在https://www.virtualbox.org/wiki/Windows%20build%20instructions中有提到:
This step will fail for a 64-bit (amd64) target if the Guest Additions are part of the build process (which is the default, disable by adding VBOX_WITH_ADDITIONS= and VBOX_WITH_ADDITIONS_PACKING= to LocalConfig.kmk, see below). It will complain about a dependency to VBoxOGL* libraries in out\win.x86\release\bin\additions. In that case, create the 32-bit Guest Additions by executing。
所以婆硬,先在LocalConfig.kmk中加入 VBOX_WITH_ADDITIONS= and VBOX_WITH_ADDITIONS_PACKING= 跳過(guò)addtions的編譯
無(wú)法解析的外部符號(hào) isprint
用2015編譯過(guò)程中狠轻,大量的link錯(cuò)誤,報(bào)錯(cuò)都是:
bin2c.obj : error LNK2019: 無(wú)法解析的外部符號(hào) isprint彬犯,該符號(hào)在函數(shù) main 中被引用
bin2c.obj : error LNK2019: 無(wú)法解析的外部符號(hào) __acrt_iob_func向楼,該符號(hào)在函數(shù) main 中被引用
bin2c.obj : error LNK2019: 無(wú)法解析的外部符號(hào) fclose,該符號(hào)在函數(shù) main 中被引用
報(bào)錯(cuò)的程序太多谐区,構(gòu)建腳本又太復(fù)雜湖蜕,經(jīng)過(guò)摸索使用bin2c這個(gè)cpp來(lái)突破,bin2c不依賴(lài)于其它virtualbox或三方庫(kù)代碼,單獨(dú)使用命令行cl即可編譯生成出exe。
經(jīng)研究,virtualbox在編譯命令行中加入了-Zl
,于是用cl -Zl bin2c.c 編譯琴庵,果然直接失敗单料,但輸出obj后在link時(shí)添加c運(yùn)行時(shí)庫(kù)能成功合瓢。
// -Zl https://msdn.microsoft.com/zh-cn/library/f1tbxcxh.aspx。 ps:-Zl這是小寫(xiě)L,不是數(shù)字1.
// 可以使用 /Zl 來(lái)編譯打算放入庫(kù)中的 .obj 文件。 雖然省略庫(kù)名只為單個(gè) .obj 文件節(jié)省了少量空間熙含,但在包含許多對(duì)象模塊的庫(kù)中節(jié)省的總空間是很多的。
cl.exe -Zl -Fobin2c.obj bin2c.c
然后使用 link.exe bin2c.obj libcmt.lib 可以鏈接通過(guò)艇纺。
但從Config.kmk中看到怎静,編譯時(shí)還是帶上了libcmt.lib的,比如:
VBoxRT_LIBS.win.x86 = \
$(PATH_TOOL_$(VBOX_VCC_TOOL_STEM)X86_LIB)/oldnames.lib \
$(PATH_TOOL_$(VBOX_VCC_TOOL_STEM)X86_LIB)/libcmt.lib \
$(PATH_TOOL_$(VBOX_VCC_TOOL_STEM)X86_LIB)/libcpmt.lib
但還是鏈接黔衡,從日志文件中提取出來(lái)最后的line命令行消约,并且精簡(jiǎn)如下:link.exe /NOD bin2c.obj libcmt.lib
,其中去掉這個(gè)/NOD
就會(huì)鏈接成功。msdn上并沒(méi)有該選項(xiàng)员帮,僅有一個(gè)/NODEFAULTLIB 在解析外部引用時(shí)忽略所有(或指定的)默認(rèn)庫(kù)。
,通過(guò)實(shí)驗(yàn)它們兩是效果相等的导饲。
但同樣是添加了/NOD選項(xiàng)捞高,用vs2010編譯就不會(huì)失敗氯材,而用2015就失敗。只好先去掉/NOD這個(gè)選項(xiàng)硝岗。
kmk_builtin_kDepObj 刪除sanity-c相關(guān)文件失敗
kmk: *** [D:/projects/virtualbox/trunk/out/obj/RuntimeBldProg/common/misc/sanity-c.obj] Error 512 (0x200)
The failing command:
@kmk_builtin_kDepObj -f -s -q -o D:/projects/virtualbox/trunk/out/obj/RuntimeBldProg/common/misc/sanity-c.obj.dep -t D:/projects/virtualbox/trunk/out/obj/RuntimeBldProg/common/misc/sanity-c.obj D:/projects/virtualbox/trunk/out/obj/RuntimeBldProg/common/misc/sanity-c.obj
kmk: *** Deleting file `D:/projects/virtualbox/trunk/out/obj/RuntimeBldProg/common/misc/sanity-c.obj'
kmk: *** Waiting for unfinished jobs....
kmk: *** Exiting with status 2
vs2015下才有此bug氢哮,原因未知,先換用2010繼續(xù)編譯
資源編譯失敗
D:/projects/virtualbox/mingw32/bin/windres: unknown format type `D:/projects/virtualbox/trunk/include'
D:/projects/virtualbox/mingw32/bin/windres: supported formats: rc res coff
原始命令行:
D:/projects/virtualbox/mingw32/bin/windres -ID:/projects/virtualbox/trunk/include -ID:/projects/virtualbox/trunk/out_vs2010 -IC:/PROGRA~2/MICROS~1/Windows/v7.1A/Include -IC:/PROGRA~2/MICROS~4.0/VC/include -DVBOX_SVN_REV=69891 -DVBOX_SVN_REV_MOD_5K=19891 D:/projects/virtualbox/trunk/src/recompiler/VBoxREM.rc D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxREMImp/VBoxREMRes.o
查看windres的幫助型檀,發(fā)現(xiàn)下載的virtualbox推薦mingw32里的windres是GNU windres (GNU Binutils) 2.25冗尤,-I參數(shù)不是輸入文件,而是指格式胀溺。
Usage: D:\projects\virtualbox\mingw32\bin\windres.exe [option(s)] [input-file] [output-file]
The options are:
-i --input=<file> Name input file
-o --output=<file> Name output file
-I --input-format=<format> Specify input format
-O --output-format=<format> Specify output format
再查看其它幾個(gè)windres發(fā)現(xiàn)是-I --input-format=<format> Specify input format
裂七,于是就從其它地方找了windres替換掉這個(gè)。
dllwrap.exe 報(bào)錯(cuò) undefined reference to `__dyn_tls_init_callback' 1
/mingw/lib/dllcrt2.o(.text+0xd1): undefined reference to `__dyn_tls_init_callback` 1
# 命令行是
D:/projects/virtualbox/mingw32/bin/dllwrap.exe -s --dllname=D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/VBoxREM32.dll --output-exp=D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/VBoxREM32.exp --output-lib=D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/VBoxREM32.a --def D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxREMImp/VBoxREMWin.def D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/VBoxRecompiler.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/cpu-exec.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/exec.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/translate-all.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/host-utils.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/cutils.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/tcg-runtime.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/tcg/tcg.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/tcg/tcg-dyngen.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/fpu/softfloat-native.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/target-i386/op_helper.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/target-i386/helper.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxRemPrimary/target-i386/translate.o D:/projects/virtualbox/trunk/out_vs2010/obj/VBoxREMImp/VBoxREMRes.o -LD:/projects/virtualbox/mingw32/lib D:/projects/virtualbox/trunk/out_vs2010/lib/VBoxVMM.lib D:/projects/virtualbox/trunk/out_vs2010/lib/VBoxRT.lib
神奇的是仓坞,去掉-LD:/projects/virtualbox/mingw32/lib或者將目錄改成我原來(lái)的D:/Mingw/lib就能正常生成dll背零。所以我覺(jué)得是virtualbox推薦的mingwruntime有問(wèn)題,所以我去下載了mingwrt-3.22.4
版本无埃,也能正常編譯徙瓶。
QT“void (__thiscall UISnapshotPane::* )(void)”轉(zhuǎn)換為“const char *”
D:\projects\virtualbox\trunk\src\VBox\Frontends\VirtualBox\src\selector\UISnapshotPane.cpp(1273) : error C2664: “QAction *QToolBar::addAction(const QIcon &,const QString &,const QObject *,const char *)”: 不能將參數(shù) 4 從“void (__thiscall UISnapshotPane::* )(void)”轉(zhuǎn)換為“const char *”
沒(méi)有使該轉(zhuǎn)換得以執(zhí)行的上下文
事實(shí)證明一開(kāi)始偷懶下載的Qt5.5.1不支持virtualbox使用的頭文件,Qt5.6.x之后有Q_QDOC宏包括起來(lái)的幾個(gè)頭文件。于是下載5.6.2版本重新編譯嫉称。這里不能下載5.7.x版本侦镇,因?yàn)?.7.x版本的不支持vs2010編譯了。
在config.kmk中的第5933行中發(fā)現(xiàn)還有對(duì)VBOX_WITH_ORACLE_QT宏的判斷织阅,這個(gè)宏最終編譯QT這些DLL的virtualBox版本壳繁。但我沒(méi)有搞懂(也沒(méi)有時(shí)間)怎么才能像官網(wǎng)版本那樣編譯出來(lái)Qt5CoreVBox.dll、Qt5GuiVBox.dll蒲稳、Qt5OpenGLVBox.dll氮趋、Qt5PrintSupportVBox.dll、Qt5WidgetsVBox.dll江耀、Qt5WinExtrasVBox.dll這幾個(gè)文件剩胁。
src/libs/xpcom18a4/python/gen_python_deps.py: No Python development package found!
其實(shí)virtualbox已經(jīng)能運(yùn)行了,但是在研究VBoxFB時(shí)使用了新的宏祥国,編譯時(shí)提示錯(cuò)誤昵观。
kmk.exe VBOX_WITH_VBOXFB=1 VBOX_WITH_XPCOM=1
但看具體代碼,似乎VBoxFB在非win系統(tǒng)下使用的舌稀。所以這個(gè)就跳過(guò)了啊犬。
安裝啟動(dòng)
解決以上bug后,編譯都順利通過(guò)壁查,然后我還繼續(xù)使用vs2010編譯了64位的qt觉至。然后編譯了64位的virtualbox。
然后將編譯中用到的libcurl和openssl相關(guān)dll放到bin目錄睡腿。 libcrypto-1_1-x64.dll语御、libcurl.dll峻贮、libssl-1_1-x64.dll,還有QT相關(guān)的6個(gè)dll应闯,Qt5Core.dll纤控、Qt5Gui.dll、Qt5OpenGL.dll碉纺、Qt5PrintSupport.dll船万、Qt5Widgets.dll、Qt5WinExtras.dll骨田。然后各種程序啟動(dòng)不報(bào)錯(cuò)耿导,但是啟動(dòng)還沒(méi)有效果。
需要按照官網(wǎng)上build instructions網(wǎng)頁(yè)上的說(shuō)法:
- 需要先注冊(cè)com進(jìn)程盛撑,以管理員權(quán)限運(yùn)行:comregister.cmd碎节。
- loadall.cmd 安裝驅(qū)動(dòng),但驅(qū)動(dòng)(.sys結(jié)尾的7個(gè)文件)需要先簽名抵卫。
- 然后就能啟動(dòng)VirtualBox.exe了狮荔。
SUPInstall.exe: error: installation failed. rc=VERR_UNRESOLVED_ERROR
在第2步安裝驅(qū)動(dòng)時(shí),提示:
+ D:/projects/virtualbox/out_vs2010_x64/bin/SUPInstall.exe
SUPInstall.exe: error: installation failed. rc=VERR_UNRESOLVED_ERROR
將所有驅(qū)動(dòng)文件生成對(duì)應(yīng)的cat文件介粘,并且將cat和sys簽名即可殖氏。