《深入理解JAVA虚拟机 ● 第三版》MacOS编译OpenJDK12

本文档详细介绍了如何在MacOS环境下编译OpenJDK12,包括编译环境的配置(如Xcode, command line tools, Homebrew),OpenJDK源码的下载,依赖库的安装,以及编译参数设置和编译过程。在编译过程中可能遇到的问题及解决方案也一并提供。" 42008889,4897901,Qt5实现个人画板:涂鸦功能详解,"['Qt', 'GUI开发', '2D绘图']
摘要由CSDN通过智能技术生成

编译环境

  • MacOS Catalina 10.15.4
  • Xcode 11.5
  • command line tools
  • Homebrew 2.2.5

编译准备

OpenJDK12源码下载

浏览器打开地址:https://hg.openjdk.java.net/jdk/jdk12/

点击左侧Browse,将显示源码根目录页面:
在这里插入图片描述
点击左侧bz2、zip、gz 中任意一个,即可下载压缩好的源码包。
在这里插入图片描述
如果下载较慢或者下载失败,可使用百度网盘下载。建议从官网下载,可以获取最新源码。
链接: OpenJDK12源码
提取密码: sbcf

安装JDK11

由于JDK源码中大部分代码还是采用JAVA语言实现,所以在编译前需要准备好另一个编译期可用的JDK,官方称此JDK为Bootstrap JDK。假设需要编译的JDK大版本号为N,我们必须准备好另外一个大版本号至少为N-1的JDK。

安装Xcode

App Store安装
在这里插入图片描述

安装command line tools

从App Store上下载的Xcode,默认是不会安装Command Line Tools的,Command Line Tools是在Xcode中的一款工具,可以在命令行中运行C程序。

打开终端,在终端中输入命令

xcode-select --install 

安装完成后,在终端中执行 gcc -v 命令查看是否安装成功。
如果显示如下内容,则安装成功。

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

安装Homebrew

进入Homebrew官网获取最新下载链接;
在这里插入图片描述
打开终端,运行拷贝的命令:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

执行过程中会要求输入密码,输入密码回车继续安装;

安装完成后,会出现 Installation successful! 字样,即安装成功。

终端运行如下命令,可查看安装的版本信息:

brew -v

输出示例:

Homebrew 2.2.5
Homebrew/homebrew-core (git revision e6c5f; last commit 2020-02-09)

安装依赖库

打开终端,执行如下命令:

brew install ccache
brew install freetype
brew install autoconf

编译JDK

编译参数

编译参数可通过在JDK源码目录下执行以下命令查询:

bash  configure --help

查询结果示例如下:

`configure' configures OpenJDK openjdk to adapt to many kinds of systems.

Usage: /Users/fcc/Project/JDKSource/jdk12-06222165c35f/configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值