Windows10編譯OpenJDK8
前言
本文基於win10(64位)編譯openjdk8,碰到各種問題被卡住,最終還好編譯完成,總結如下,希望對你有幫助
1. 環境準備
- Windows 10
- oracleJDK8
- 官方下載地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- 選擇windows x64下載
- 需要登錄,可以查看這篇:https://blog.csdn.net/Virgil_K2017/article/details/90260880
- Openjdk8源碼
- Cygwin
- 官方下載鏈接:http://www.cygwin.com/setup-x86_64.exe
- 安裝幫助博客:https://blog.csdn.net/u010356768/article/details/90756742
- 推薦一個工具apt-cyg,在安裝cygwin時,一定要先安裝wget. 然後從github上下載https://github.com/transcode-open/apt-cyg,放在cygwin的/usr/local/bin目錄下,
chmod +x apt-cyg
加上可執行權限,然後可以通過apt-cyg install 下載我們需要的包
- freetype
- 官方源碼下載鏈接:https://sourceforge.net/projects/freetype/files/freetype2/2.8.1/freetype-2.8.1.tar.gz/download
- dll、lib文件:https://github.com/ubawurinna/freetype-windows-binaries
- 可以自己從源碼編譯,也可以直接使用已經編譯好的文件
- VS2010
2. 軟件安裝重點
- 將vs2010安裝目錄下VC\bin 加入PATH中
- 根據README-builds.md ,cygwin需要安裝以下工具
- ar
- make
- m4
- cpio
- gawk
- file
- zip
- unzip
- free
3. configure
將–with-freetype的目錄指向編譯好的freetype目錄,以下是我的configure執行命令,如果沒有配置oracle java環境變量,需要配置--with-boot-jdk
./configure --with-freetype=/cygdrive/c/Users/supre/Desktop/openjdk8/openjdk-8/freetype --with-target-bits=64 --enable-debug
報錯
-
–with-freetype配置不對報錯,最好使用絕對路徑
configure: error: Can not find or use freetype at location given by --with-freetype
-
Your cygwin is too old
configure: Your cygwin is too old. You are running 2.11.1(0.329/5/3), but at least cygwin 1.7 is required. Please upgrade.
解決方法:common\autoconf\generated-configure.sh搜索Your cygwin is too old,將第7220行的1.7修改爲自己cygwin版本號,我的就是修改爲2.11
-
Target CPU mismatch,中文版vs造成的
configure: error: Target CPU mismatch. We are building for x86_64 but CL is for""; expected "x64"
解決方法:common\autoconf\generated-configure.sh 查找Target CPU mismatch. We are building, 將相關代碼註釋, 20043-20051行和21622-21630行註釋掉
4. make
在configure完成的目錄下執行make命令
make
報錯
-
fatal error U1073: 不知道如何生成xinclude.mod
NMAKE : fatal error U1073: 不知道如何生成“C:\Users\supre\Desktop\openjdk8\openjdk-8\hotspot/src/share/vm/trace/xinclude.mod” Stop. NMAKE : fatal error U1077: “cd”: 返回代碼“0x2” Stop. NMAKE : fatal error U1077: “"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\nmake.EXE"”: 返回代碼“0x2”
解決方法:這個報錯在網上沒有找到類似的解決方法,後來發現是我下的這個openjdk源碼少了xinclude.mod這個文件,重新從官網下了一個放在給定的目錄就OK了
-
integer expressionexpected錯誤
## Starting hotspot make[2]: warning: -jN forced in submake: disabling jobserver mode. INFO: ENABLE_FULL_DEBUG_SYMBOLS=1 C:\Users\supre\Desktop\openjdk8\openjdk-8\hotspot/make/windows/get_msc_ver.sh: line 65: [: 用於 x64 的 Microsoft (R) C/C++ 優化編譯器 16: integer expressionexpected /usr/bin/expr: syntax error NMAKE : fatal error U1077: “sh”: 返回代碼“0x2”
解決方法:在hotspot\make\windows\get_msc_ver.sh 將65-70註釋,改爲
MSC_VER_RAW=16.00.303109.01 MSC_VER=1600
具體版本,可以根據cl.exe執行得到版本信息,這個是因爲中文版vs輸出中文信息,腳本是根據英文版寫的,不能得到版本信息,我的vs cl版本如下
用於 x64 的 Microsoft (R) C/C++ 優化編譯器 16.00.30319.01 版
5.make install
make完成後,需要執行make install 將生成的文件集中在某個目錄,沒有指定默認放在/usr/local/jvm下
make install
-
Exception in thread “main” java.lang.VerifyError: class
Running nasgen Exception in thread "main" java.lang.VerifyError: class jdk.nashorn.internal.objects.ScriptFunctionImpl overrides final method setPrototype.(Ljava/lang/Object;)
解決方法: nashorn/make/BuildNashorn.gmk 80行原來 -cp 修改爲:-Xbootclasspath/p:
-
error CreateJars.gmk:268
make[2]: *** [CreateJars.gmk:268: /cygdrive/c/Users/supre/Desktop/openjdk8/openjdk-8-master/build/windows-x86_64-normal-server-release/images/lib/_the.rt.jar.contents] Error 1 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [BuildJdk.gmk:101: images] Error 2 make: *** [/cygdrive/c/Users/supre/Desktop/openjdk8/openjdk-8-master//make/Main.gmk:136: images-only] Error7 2
解決方法:
- 用vi打開jdk/make目錄下的CreateJars.gmk
- 按esc 進入命令模式, 輸入268gg回車定位到268行,相距不遠處有兩個$$換行符,將其轉換爲Windows下的換行符。
- 將光標定位到兩個$$之前,按i切換到insert模式後,按Ctrl + V, Ctrl + M,即可打出^M
- 完成後按esc退出編輯模式,然後按:進入命令模式,輸入wq保存並退出
- make clean, 重新make
完成
在/usr/local/jvm就有生成的openjdk-1.8.0-internal文件夾,執行java -version
openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.0-internal-supre_2019_12_19_22_37-b00)
OpenJDK 64-Bit Server VM (build 25.0-b70, mixed mode)