windows环境下编译OpenJDK12

news2024/10/5 20:20:01

环境:Windows11

目录:

1、下载OpenJDK12源码

下载地址:

https://hg.openjdk.org/jdk/jdk12

Untitled.png

点击zip下载到本地。

解压到本地。

Tip:注意本地路径中最好不要包含中文或空格。

2、阅读一遍doc/building.html

如果只是想构建JDK,又没耐心看完那么多内容,只要看 TL;DR (Instructions for the Impatient) 部分的内容就可以了 😃

构建步骤主要为以下5步:

1、获取源码(http://hg.openjdk.java.net/jdk/jdk)

2、运行配置(bash configure)

3、运行make(make images)

4、验证是否构建成功(./build/*/images/jdk/bin/java -version)

5、运行基本测试(make run-test-tier1)

3、安装CYGWIN

CYGWIN是一个用于在windows上模拟UNIX或LINUX环境的软件,在其上可使用GNU工具集在Windows上进行嵌入式系统开发。

之所以要下载这个软件,是因为后面编译OpenJDK的时候,需要用GNU Make来执行Makefile文件。

下载地址:
Cygwin

安装教程:

Windows环境运行Linux命令——Cygwin安装_难拳的博客-CSDN博客

4、安装Visual Studio 2022(C++编译器)

Untitled 1.png

官网下载地址:https://visualstudio.microsoft.com/zh-hans/vs/

5、配置依赖

打开控制台,输入 bash ,进入Bourne Again Shell环境:

Untitled 2.png

进入OpenJDK12源码解压后的路径,输入 bash configure:

Untitled 3.png

编译FastDebug版、仅含Server模式的HotSpot虚拟机:

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

Tip:如果之前执行过配置命令,需要先清除一下目录:make dist-clean

配置踩坑合集

报错1:

Untitled 4.png

configure: Your path contains Windows tools (C:\Windows\system32) before your unix (cygwin or msys) tools. configure: This will not work. Please correct and make sure /usr/bin (or similar) is first in path. configure: error: Cannot continue configure exiting with result code 1

解决方案1:

bash --login -i 进入shell环境

报错2:

configure: Could not find a valid Boot JDK.
configure: error: Cannot continue
configure: This might be fixed by explicitly setting --with-boot-jdk
configure exiting with result code 1

解决方案2:

下载JDK11:https://www.oracle.com/java/technologies/downloads/#java11

安装完成后,执行:

bash configure --enable-debug --with-jvm-variants=server --with-boot-jdk=/cygdrive/d/jdk11

指定boot jdk路径:-with-boot-jdk=/cygdrive/d/jdk11

报错3:

configure: Cannot locate a valid Visual Studio installation, checking current environment
checking for Visual Studio variables... not found
configure: Cannot locate a valid Visual Studio or Windows SDK installation on disk,
configure: nor is this script run from a Visual Studio command prompt.
configure: Try setting --with-tools-dir to the VC/bin directory within the VS installation
configure: or run "bash.exe -l" from a VS command prompt and then run configure from there.
configure: error: Cannot continue
configure exiting with result code 1

解决方案3:

bash configure --enable-debug --with-jvm-variants=server --with-boot-jdk=/cygdrive/d/jdk11 --with-tools-dir=/cygdrive/d/software/vs2019/VC/Auxiliary/Build

指定:-with-tools-dir=/cygdrive/d/software/vs2019/VC/Auxiliary/Build

同时注释掉OpenJDK12源码中make/autoconf/toolchain_windows.m4文件中的这句:

#VS_ENV_CMD=""

以及make/autoconf/toolchain.m4中的:

#AC_MSG_ERROR([A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir.])

报错4:

configure: Rewriting OBJDUMP to "/usr/bin/objdump"
configure: error: Target CPU mismatch. We are building for x86_64 but CL is for "□□"; expected "x64".
configure exiting with result code 1

解决方案4:

在make/autoconf/toolchain.m4中找到Target CPU mismatch对应的AC_MSG_ERROR,改成AC_MSG_NOTICE。

报错5:

configure: Rewriting CYGWIN_VC_INSTALL_DIR to "/cygdrive/d/software/vs2019/VC"
ls: cannot access '/cygdrive/d/software/vs2019/VC/Redist/MSVC/*/x64/Microsoft.VC141.CRT/vcruntime140.dll': No such file or directory
configure: Found vcruntime140.dll at /cygdrive/d/jdk11/bin/vcruntime140.dll using well-known location in Boot JDK
checking found vcruntime140.dll architecture... ok
checking for vcruntime140.dll... /cygdrive/d/jdk11/bin/vcruntime140.dll
configure: Rewriting CYGWIN_VC_INSTALL_DIR to "/cygdrive/d/software/vs2019/VC"
ls: cannot access '/cygdrive/d/software/vs2019/VC/Redist/MSVC/*/x64/Microsoft.VC141.CRT/msvcp140.dll': No such file or directory
configure: Found msvcp140.dll at /cygdrive/d/jdk11/bin/msvcp140.dll using well-known location in Boot JDK
checking found msvcp140.dll architecture... ok
checking for msvcp140.dll... /cygdrive/d/jdk11/bin/msvcp140.dll
checking for UCRT DLL dir... configure: Rewriting CYGWIN_WINDOWSSDKDIR to "/cygdrive/c/progra~2/wi3cf2~1/10"
no
configure: error: Could not find any dlls in /cygdrive/c/progra~2/wi3cf2~1/10/Redist/ucrt/DLLs/x64
configure exiting with result code 1

解决方案5:

toolchain_window.m4文件中的

UCRT_DLL_DIR="$CYGWIN_WINDOWSSDKDIR/Redist/ucrt/DLLs/$dll_subdir"

中间加上对应的版本号:

UCRT_DLL_DIR="$CYGWIN_WINDOWSSDKDIR/Redist/10.0.19041.0(版本号,在c/progra~2/wi3cf2~1/10/Redist下)/ucrt/DLLs/$dll_subdir"

再次执行:

bash configure --enable-debug --with-jvm-variants=server --with-boot-jdk=/cygdrive/d/jdk11 --with-tools-dir=/cygdrive/d/software/vs2019/VC/Auxiliary/Build

终于配置成功:

Untitled 5.png

6、编译

先执行make clean清除旧配置

Untitled 6.png

执行make images编译:

编译踩坑合集

报错1:

Untitled 7.png

解决1:

摸进e/jdk12-06222165c35f/build/windows-x86_64-server-fastdebug/make-support/failure-logs的错误日志里看看:

Untitled 8.png

这个test_json.cpp文件里有语法错误,是文件编码的问题,把文件编码改为utf-8-bom格式。

再次执行make clean和make images:

报错2:

Untitled 9.png

解决2:

看到test_json.cpp的357和363等行里都有一个小雪人字符:

Untitled 10.png

把所有雪人字符都替换成普通字母,再次执行make clean和make images:

报错3:

Untitled 11.png

解决3:

找到methodMatcher.cpp,在240行后加上这三句:

Untitled 12.png

    #pragma warning(disable: 4819)
    #pragma warning(disable: 4778)
    #pragma warning(disable: 4474)

报错4:

Untitled 13.png

error C2039: "Do_Not_Use_calloc_Use_safe_Calloc_Instead": 不是 "`global namespace'" 的成员
error C2873: “Do_Not_Use_calloc_Use_safe_Calloc_Instead”: 符号不能用在 using 声明中
error C2039: "Do_Not_Use_malloc_Use_safe_Malloc_Instead": 不是 "`global namespace'" 的成员
error C2873: “Do_Not_Use_malloc_Use_safe_Malloc_Instead”: 符号不能用在 using 声明中
error C2039: "Do_Not_Use_realloc_Use_safe_Realloc_Instead": 不是 "`global namespace'" 的成员
error C2873: “Do_Not_Use_realloc_Use_safe_Realloc_Instead”: 符号不能用在 using 声明中

解决4:

找到src\java.desktop\windows\native\libawt\windows\alloc.h,将文件格式改为utf-8-bom。

并将87行开始的下面这三句注释掉:

#define malloc Do_Not_Use_malloc_Use_safe_Malloc_Instead
#define calloc Do_Not_Use_calloc_Use_safe_Calloc_Instead
#define realloc Do_Not_Use_realloc_Use_safe_Realloc_Instead

报错5:

Building target 'images' in configuration 'windows-x86_64-server-fastdebug'
Warning: No SCM configuration present and no .src-rev
make[3]: *** No rule to make target '/cygdrive/e/jdk12/build/windows-x86_64-server-fastdebug/buildtools/langtools_tools_classes/_the.BUILD_TOOLS_LANGTOOLS.vardeps', needed by '/cygdrive/e/jdk12/build/windows-x86_64-server-fastdebug/buildtools/langtools_tools_classes/_the.BUILD_TOOLS_LANGTOOLS_batch'.  Stop.
make[3]: *** Waiting for unfinished jobs....
make[3]: *** No rule to make target '/cygdrive/e/jdk12/build/windows-x86_64-server-fastdebug/make-support/vardeps/make/ReleaseFile.gmk/create-info-file.vardeps', needed by '/cygdrive/e/jdk12/build/windows-x86_64-server-fastdebug/jdk/release'.  Stop.
make[2]: *** [make/Main.gmk:369: release-file] Error 2
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [make/Main.gmk:73: buildtools-langtools] Error 2
make[3]: *** No rule to make target '/cygdrive/e/jdk12/build/windows-x86_64-server-fastdebug/make-support/vardeps/make/ModuleWrapper.gmk/java.base/ORDERED_CFG_VARIANTS.vardeps', needed by '/cygdrive/e/jdk12/build/windows-x86_64-server-fastdebug/support/modules_libs/java.base/jvm.cfg'.  Stop.
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [make/Main.gmk:162: java.base-copy] Error 2

解决5:

参见 windows 平台编译openjdk12 - 乐途 - 博客园

make -v,检查一下Cygwin里make的版本,我的版本不知道什么时候改成了4.4,在Cygwin里卸载掉就可以了。

解决完所有报错后,执行 make images

编译成功

Untitled 15.png

7、安装IDE:CLion

1)CLion安装教程:

https://www.kdocs.cn/l/cvdh8F64PEfQ?openfrom=docs

2)打开OpenJDK项目:选择Open Project

Untitled 16.png

3)CLion配置Cygwin(Cygwin安装教程见上一章上机实验):

Setting>Toolchains

Untitled 17.png

4)CLion配置编译参数:

Setting>Custom Build Targets

Untitled 18.png

点击Build和Clean右侧的…配置对应的External Tools:

Untitled 19.png

  • CONF=windows-x86_64-server-fastdebug(在jdk编译后的build目录下)

Untitled 20.png

Untitled 21.png

Untitled 22.png

AddConfiguration>Custom Build Application

Untitled 23.png

运行:

Untitled 24.png

正确输出版本号,测试成功:

Untitled 25.png

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/845889.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

C++11 新特性 ---- 原始字面量

一、原始字面量 R “xxx(原始字符串)xxx”&#xff0c;其中&#xff08;&#xff09;两边的字符串可以省略。 #include <iostream> #include <string> using namespace std; int main() {string str1 R"(D:\hello\heheda\test.txt)";string str2 R&q…

dfs之卒的遍历

题面 题目描述 在一张nm 的棋盘上&#xff08;如 6 行 7 列&#xff09;的最左上角(1,1) 的位置有一个卒。该卒只能向下或者向右走&#xff0c;且卒采取的策略是先向下&#xff0c;下边走到头就向右&#xff0c;请问从(1,1) 点走到 (n,m) 点可以怎样走&#xff0c;输出这些走法…

TM4C123库函数学习(1)--- 点亮LED+TM4C123的ROM函数简介+keil开发环境搭建

前言 &#xff08;1&#xff09; 首先&#xff0c;我们需要知道TM4C123是M4的内核。对于绝大多数人而言&#xff0c;入门都是学习STM32F103&#xff0c;这款芯片是采用的M3的内核。所以想必各位对M3内核还是有一定的了解。M4内核就是M3内核的升级版本&#xff0c;他继承了M3的的…

pka 预测汇总

汇总内容来自 Open-Source Machine Learning in Computational Chemistry 中表格涉及的内容 文章目录 1.DeepKa2.Machine learning meets pKa 1.DeepKa 预测蛋白质的 pka&#xff0c;文章是 Basis for Accurate Protein p Ka Prediction with Machine Learning 和 Protein p…

web-csrf

目录 CSRF与XSS的区别&#xff1a; get请求 原理&#xff1a; pikachu为例 post请求 pikachu为例 CSRF与XSS的区别&#xff1a; CSRF是借用户的权限完成攻击&#xff0c;攻击者并没有拿到用户的权限&#xff0c;而XSS是直接盗取到了用户的权限 get请求 原理&#xff1a;…

20230807在WIN10下使用python3将TXT文件转换为DOCX(在UTF8编码下转换为DOCX有多一行的瑕疵)

20230807在WIN10下使用python3将TXT文件转换为DOCX&#xff08;在UTF8编码下转换为DOCX有多一行的瑕疵&#xff09; 2023/8/7 12:58 https://translate.google.com/?slen&tlzh-CN&opdocs 缘起&#xff0c;由于google的文档翻译不支持SRT/TXT格式的字幕&#xff0c;因此…

利用Arthas+APM监控进行Java性能深度定位

大家可能都用过APM监控&#xff0c;包括开源的Skywalking、商用的卓豪&#xff08;ZOHO&#xff09;ManageEngine APM应用性能监控、以及云监控产品如听云&#xff08;Server监控&#xff09;&#xff0c;这些APM监控产品大大方便了我们实时监控应用性能&#xff0c;并实现性能…

04-6_Qt 5.9 C++开发指南_QListWidget和QToolButton

文章目录 1. 实例简介2. 源码2.1 混合式界面设计2.2 mainwindow.h2.3 mainwindow.cpp 1. 实例简介 Qt 中用于项 (Item)处理的组件有两类&#xff0c;一类是 Item Views&#xff0c;包括 QListView、QTreeView、QTableView、QColumnView 等;另一类是 Item Widgets&#xff0c;包…

用html+javascript打造公文一键排版系统14:为半角和全角字符相互转换功能增加英文字母、阿拉伯数字、标点符号、空格选项

一、实际工作中需要对转换选项细化内容 在昨天我们实现了最简单的半角字符和全角字符相互转换功能&#xff0c;就是将英文字母、阿拉伯数字、标点符号、空格全部进行转换。 在实际工作中&#xff0c;我们有时只想英文字母、阿拉伯数字、标点符号、空格之中的一两类进行转换&a…

FTP Server(二)

问题 使用Centos8通过命令行登录FTP服务器后发现乱码&#xff0c;无法显示中文 原因 FTP服务器是windows系统使用的是GBK编码&#xff0c;大多数Linux版本默认使用的是UTF-8 解决 在家目录下新建编辑 .lftprc 文件 [rootwenzi ~]#pwd /root [rootwenzi ~]#vim .lftprc debu…

狂神说-通俗易懂的23种设计模式

狂神说-通俗易懂的23种设计模式 文章目录 1、设计模式概述2、OOP七大原则4、工厂模式5、抽象工厂模式6、建造者模式7、原型模式8、适配器模式9、桥接模式10、静态代理模式11、静态代理再理解12、动态代理详解 1、设计模式概述 设计模式的基本要素&#xff1a; 1、模式名称 2、…

以太网DHCP协议(十)

目录 一、工作原理 二、DHCP报文 2.1 DHCP报文类型 2.2 DHCP报文格式 当网络内部的主机设备数量过多是&#xff0c;IP地址的手动设置是一件非常繁琐的事情。为了实现自动设置IP地址、统一管理IP地址分配&#xff0c;TCPIP协议栈中引入了DHCP协议。 一、工作原理 使用DHCP之…

2022 robocom 世界机器人开发者大赛-本科组(国赛)

RC-u1 智能红绿灯 题目描述&#xff1a; RC-u1 智能红绿灯 为了最大化通行效率同时照顾老年人穿行马路&#xff0c;在某养老社区前&#xff0c;某科技公司设置了一个智能红绿灯。 这个红绿灯是这样设计的&#xff1a; 路的两旁设置了一个按钮&#xff0c;老年人希望通行马路时会…

C语言预处理命令 #error 学习

#error命令是C/C语言的预处理命令之一&#xff0c;当预处理器预处理到#error命令时将停止编译并输出用户自定义的错误消息。 如下代码输出数字1000&#xff0c;如果加了 #error&#xff0c;构建时不会通过&#xff0c;提示出错如下&#xff1b; 这可能在大型项目中比较有用&am…

前端小练--社区主页

文章目录 前言首页结构固定导航栏左侧导航itemitem标志 头部推荐文章展示ITEM实现ToolTip完整实现 首页完整实现 前言 废话不多说&#xff0c;直接看到效果&#xff1a; 是的也许你已经发现了这个页面和某个网站长得贼像。没错是这样的&#xff0c;这个布局我确实看起来很舒服…

【Rust】Rust学习 第五章使用结构体组织相关联的数据

5.1 定义结构体并实例化结构体 定义结构体&#xff0c;需要使用 struct 关键字并为整个结构体提供一个名字。结构体的名字需要描述它所组合的数据的意义。接着&#xff0c;在大括号中&#xff0c;定义每一部分数据的名字和类型&#xff0c;我们称为 字段&#xff08;field&…

从进程pid反推获得该进程所属容器

参考链接 https://cloud-atlas.readthedocs.io/zh_CN/latest/docker/debug/get_container_by_pid.html

基于Java+SpringBoot+Vue的生鲜交易系统设计与实现(源码+LW+部署文档等)

博主介绍&#xff1a; 大家好&#xff0c;我是一名在Java圈混迹十余年的程序员&#xff0c;精通Java编程语言&#xff0c;同时也熟练掌握微信小程序、Python和Android等技术&#xff0c;能够为大家提供全方位的技术支持和交流。 我擅长在JavaWeb、SSH、SSM、SpringBoot等框架…

Idea使用Docker插件实现maven打包自动构建镜像

Docker 开启TCP 服务 vi /lib/systemd/system/docker.service改写以下内容 ExecStart/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock重启服务 #重新加载配置文件 systemctl daemon-reload #重启服务 systemctl restart docker.service此时docker已…

支付模块功能实现(小兔鲜儿)【Vue3】

支付 渲染基础数据 支付页有俩个关键数据&#xff0c;一个是要支付的钱数&#xff0c;一个是倒计时数据&#xff08;超时不支付商品释放&#xff09; 准备接口 import request from /utils/httpexport const getOrderAPI (id) > {return request({url: /member/order/$…