Centos8下编译Openjdk12

FoxHound

周末尝试在Centos8系统下对OpenJdk12进行编译,下面是流水账:

1.下载源码
方法1(外网速度慢):
下载mercurial:

> yum -y install hg

下载openjdk12源码:

> hg clone http://hg.openjdk.java.net/jdk/jdk

方法2(通过github下载):
https://github.com/unofficial...

2.构建环境
下载GCC Clang编译器:

> sudo yum -y groupinstall "Development Tools"

安装第三方类库和工具
FreeType:

> sudo yum -y install freetype-devel

CUPS:

> sudo yum -y install cups-devel

X11:

> sudo yum -y install libXtst-devel libXt-devel libXrender-devel libXrandr-devel libXi-devel

ALSA:

> sudo yum -y install alsa-lib-devel

libffi:

> sudo yum -y install libffi-devel

Autoconf:

> sudo yum -y install autoconf

安装编译用jdk:

> yum -y install java-11-openjdk-devel

3.进行编译
进入到源码目录

> cd ~/opt/java/jdk12-06222165c35f

编译前设置

> bash configure

进行编译

> make images

4.遇到错误
错误信息:

/root/opt/java/jdk12-06222165c35f/src/hotspot/share/runtime/arguments.cpp: In static member function ‘static jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs*, bool*, JVMFlag::Flags)’:
/root/opt/java/jdk12-06222165c35f/src/hotspot/share/runtime/arguments.cpp:2472:29: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
         char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtArguments), tail, len);
                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/root/opt/java/jdk12-06222165c35f/src/hotspot/share/runtime/arguments.cpp:2471:44: note: length computed here
         size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
                                      ~~~~~~^~~~~~
cc1plus: all warnings being treated as errors

引发错误的原因是这段[-Werror=stringop-truncation],GCC在8.0之后的版本加入了
stringop truncation的验证警告,这里是因为出现了警告导致编译不通过,那就禁止
掉警告再进行编译。

5.再次编译
设置加入忽视警告选项

> bash configure --disable-warnings-as-errors

清理上回编译残留

> make clean
> make dist-clean

编译

> make images

6.验证结果

> ~/opt/java/jdk12-06222165c35f/build/linux-x86_64-server-release/jdk/bin/java -version
[root@localhost jdk12-06222165c35f]# ~/opt/java/jdk12-06222165c35f/build/linux-x86_64-server-release/jdk/bin/java -version
openjdk version "12-internal" 2019-03-19
OpenJDK Runtime Environment (build 12-internal+0-adhoc.root.jdk12-06222165c35f)
OpenJDK 64-Bit Server VM (build 12-internal+0-adhoc.root.jdk12-06222165c35f, mixed mode)

微信图片_20200517234749.png

阅读 1.1k
1 声望
0 粉丝
0 条评论
你知道吗?

1 声望
0 粉丝
宣传栏