Windows 10 + WSL(ubuntu 20.04) + CLion 编译JDK12

1. 编译JDK

参考:

《深入理解Java虚拟机(第三版)》

ubuntu20.04.2环境下openjdk12源码编译相关问题

Tips & Tricks: Develop OpenJDK in CLion with Pleasure

平台及工具:
Windows 10 + WSL(ubuntu 20.04) + CLion

1.1 编译问题

根据《深入理解Java虚拟机(第三版)》的步骤下载JDK源码以及安装各种编译工具,然后需要执行

bash configure --enable-debug --with-jvm-variants=server

这里会检查系统中是否安装了必须的编译工具,如果不通过,会告诉你安装哪些工具,如果没有问题再执行

make images

此时编译可能会失败,报错

=== Output from failing command(s) repeated here ===
* For target hotspot_variant-server_libjvm_objs_arguments.o:
In file included from /usr/include/string.h:495,
                 from /home/hx/OpenJDK12/src/hotspot/share/utilities/globalDefinitions_gcc.hpp:35,
                 from /home/hx/OpenJDK12/src/hotspot/share/utilities/globalDefinitions.hpp:32,
                 from /home/hx/OpenJDK12/src/hotspot/share/utilities/align.hpp:28,
                 from /home/hx/OpenJDK12/src/hotspot/share/runtime/globals.hpp:29,
                 from /home/hx/OpenJDK12/src/hotspot/share/memory/allocation.hpp:28,
                 from /home/hx/OpenJDK12/src/hotspot/share/classfile/classLoaderData.hpp:28,
                 from /home/hx/OpenJDK12/src/hotspot/share/precompiled/precompiled.hpp:34:
In function ‘char* strncpy(char*, const char*, size_t)’,
    inlined from ‘static jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs*, bool*, JVMFlag::Flags)’ at /home/hx/OpenJDK12/src/hotspot/share/runtime/arguments.cpp:2472:29:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: error: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
   ... (rest of output omitted)

* All command lines available in /home/hx/OpenJDK12/build/linux-x86_64-server-fastdebug/make-support/failure-logs.
=== End of repeated output ===

原因是gcc高版本会默认把warning当作error来处理,这样导致编译无法通过,解决方法是修改执行为

bash configure --disable-warnings-as-errors --enable-debug --with-jvm-variants=server

在执行make images之前记得执行make cleanmake dist-clean清除build文件

1.2 CLion配置问题

如果我们需要使用CLion来Debug或者编译修改后的JDK,可以按照Tips & Tricks: Develop OpenJDK in CLion with Pleasure来操作,但是在Step 3: Generate Run Configurations and Build Targets这一步会有所不同,因为示例使用的是MacOS,而WSL有所不同

在这里插入图片描述
在这里插入图片描述

  • Program:表示需要使用Windows上某个程序,显然这里如果填make则使用的是Windows下的make,而不是WSL中的make,所以这里需要填wsl
  • Arguments:表示Program后跟着的参数,而在Windows命令行工具中是可以通过wsl make来调用WSL中的程序的,所以参数部分填make即可;
  • CONF:这里没有使用CONF参数,因为之前我们在bash configure时已经指定了编译--enable-debug,所以这里不需要重复指定,默认会编译linux-x86_64-server-fastdebug

1.3 CLion断点调试问题

一般我们的WSL工具里使用的是GDB调试,所以在断点调试时会遇到sigsegv segmentation fault问题,需要配置GDB忽略项,编辑文件~/.gdbinit

handle SIGSEGV nostop noprint pass
handle SIGBUS nostop noprint pass
handle SIGFPE nostop noprint pass
handle SIGPIPE nostop noprint pass
handle SIGILL nostop noprint pass
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值