admin管理员组

文章数量:1631138

0 下载JDK11源码

git clone https://github/openjdk/jdk11.git

1 准备Cygwin

  Windows操作系统不符合POSIX标准。但是有个工具可以解决这个问题,那就是cygwin。下载链接是Cygwin。然后是安装cygwin命令。代码如下:

PS > .\setup-x86_64.exe -q -P autoconf -P make -P unzip -P zip

  注意要把Cygwin在环境变量path里排第一位,否则会报以下错误:

  反正我的环境变量,无论是用户变量和系统变量,都把Cygwin放第一位:

2 准备C/C++编译工具

  最高只能用Visual Studio 2017.如果没有,那就去下载吧。并且按照以下组件。

3 手动删除\r

  Windows可能会将换行符变成\r\n。这样configure的时候会报错,如下图:

4 下载一个JDK10

  JDK10下载地址

5 配置操作系统为英文版


  为什么要这么做?
  因为失败日志里有这么一段:

  而错误来自于这段代码:

$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Microsoft.*Compiler" > /dev/null
    if test $? -ne 0; then
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
printf "%s\n" "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: The result from running it was: \"$COMPILER_VERSION_OUTPUT\"" >&5
printf "%s\n" "$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 Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64

  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x64

  注意,这两个cl.exe的SHA-256校验码是一样的,表明其内容一样。把我逼得没办法,我用了什么方法让它输出英文呢?我把原先的VC目录重命名了,把Community目录里的VC拷贝过来了。

6 执行configure命令

bash configure --with-msvcr-dll=/cygdrive/c/msvcr100.dll --with-boot-jdk="C:\Program Files\Java\jdk-10.0.2" --with-tools-dir="
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC"

  执行还是非常成功的

7 make

  编译命令很简单,可惜我编译失败了:

  后来才知道,应该用Windows Server 2012 R2这个操作系统,可惜我是Windows10啊。

本文标签: 步骤Windows