git clone https://github.com/openjdk/jdk11.git1 准备Cygwin
Windows操作系统不符合POSIX标准。但是有个工具可以解决这个问题,那就是cygwin。下载链接是Cygwin。然后是安装cygwin命令。代码如下:
PS > .setup-x86_64.exe -q -P autoconf -P make -P unzip -P zip
注意要把Cygwin在环境变量path里排第一位,否则会报以下错误:
反正我的环境变量,无论是用户变量和系统变量,都把Cygwin放第一位:
最高只能用Visual Studio 2017.如果没有,那就去下载吧。并且按照以下组件。
Windows可能会将换行符变成rn。这样configure的时候会报错,如下图:
JDK10下载地址
5 配置操作系统为英文版
为什么要这么做?
因为失败日志里有这么一段:
而错误来自于这段代码:
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Microsoft.*Compiler" > /dev/null
if test $? -ne 0; then
{ printf "%sn" "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
printf "%sn" "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
{ printf "%sn" "$as_me:${as_lineno-$LINENO}: The result from running it was: "$COMPILER_VERSION_OUTPUT"" >&5
printf "%sn" "$as_me: The result from running it was: "$COMPILER_VERSION_OUTPUT"" >&6;}
as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
fi
"用于 x64 的 Microsoft ® C/C++ 优化编译器 19.16.27039 版"与正则表达式"Microsoft.*Compiler"肯定不匹配,那么返回退出码肯定不是0,if test $? -ne 0是退出码的判断。这是JDK源码的一个不完善的部分,不兼容中文windows操作系统。
打开Visual Studio修改语言为与操作系统相同的英文。
启动Visual Studio安装包安装英文语言包:
一切就绪后,会出现一个奇怪的现象,那就是两个路径的cl执行结果不一样,一个中文一个英文:
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsVCToolsMSVC14.16.27023binHostx64x64
C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023binHostx86x64
注意,这两个cl.exe的SHA-256校验码是一样的,表明其内容一样。把我逼得没办法,我用了什么方法让它输出英文呢?我把原先的VC目录重命名了,把Community目录里的VC拷贝过来了。
bash configure --with-msvcr-dll=/cygdrive/c/msvcr100.dll --with-boot-jdk="C:Program FilesJavajdk-10.0.2" --with-tools-dir=" C:Program Files (x86)Microsoft Visual Studio2017CommunityVC"
执行还是非常成功的
编译命令很简单,可惜我编译失败了,明天继续:



