深夜里安静的编译一个OpenJDK8,坑太多
Mac系统安装
利用brew search查找mercurial➜ ~ brew search mercurial
安装
➜ ~ brew install mercuria
Linux系统安装
sudo apt install mercurial
安装openjdk8
添加代理
一般在下载代码的时候都会很慢,故先配置好代理。我这里是V2Ray。
vim /usr/local/etc/mercurial/hgrc[http_proxy]
host=127.0.0.1:8001
[https_proxy]
host=127.0.0.1:8001
下载jdk8u的代码
hg clone https://hg.openjdk.java.net/jdk8u/jdk8u openjdk8chmod u+x get_source.sh
chmod u+x configure
./get_source.sh # 下载全部源代码
./configure --with-freetype-include=/usr/local/include/freetype2 --with-freetype-lib=/usr/local/lib/ # configure 编译环境,若编译报错,需要添加 `--disable-warnings-as-errors`
make all
漫长的等待,终于等到你
## Finished docs (build time 00:01:52)----- Build times -------
Start 2020-05-24 03:18:37
End 2020-05-24 03:30:07
00:00:19 corba
00:00:46 demos
00:01:52 docs
00:02:53 hotspot
00:01:28 images
00:00:12 jaxp
00:00:18 jaxws
00:03:07 jdk
00:00:26 langtools
00:00:09 nashorn
00:11:30 TOTAL
-------------------------
Finished building OpenJDK for target "all"
如何在CLion里面做调试,后面我再详细的写一篇。敬请期待~
遇到的坑
问题一:Xcode 4 is required to build JDK 8
configure: error: Xcode 4 is required to build JDK 8, the version found was 11.4.1. Use --with-xcode-path to specify the location of Xcode 4 or make Xcode 4 active by using xcode-select.configure exiting with result code 1
解决方案:
➜ openjdk8 vim common/autoconf/generated-configure.sh# Fail-fast: verify we"re building on Xcode 4, we cannot build with Xcode 5 or later
#XCODE_VERSION=`$XCODEBUILD -version | grep "^Xcode " | sed "s/Xcode //"`
#XC_VERSION_PARTS=( ${XCODE_VERSION//./ } )
#if test ! "${XC_VERSION_PARTS[0]}" = "4"; then
# as_fn_error $? "Xcode 4 is required to build JDK 8, the version found was $XCODE_VERSION. Use --with-xcode-path to specify the l ocation of Xcode 4 or make Xcode 4 active by using xcode-select." "$LINENO" 5
#fi
问题二:A gcc compiler is required
configure: error: A gcc compiler is required. Try setting --with-tools-dir.configure exiting with result code
# 第一处代码 elif test "x$TOOLCHAIN_TYPE" = xgcc; then
# gcc --version output typically looks like
# gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
# Copyright (C) 2013 Free Software Foundation, Inc.
# This is free software; see the source for copying conditions. There is NO
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
# Check that this is likely to be GCC.
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null
# 条件语句注释掉
# if test $? -ne 0; then
# { $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
# $as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
# { $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with --version was: "$COMPILER_VERSION"" >&5
# $as_echo "$as_me: The result from running with --version was: "$COMPILER_VERSION"" >&6;}
# as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
# fi
# 第二处代码,
elif test "x$TOOLCHAIN_TYPE" = xgcc; then
# gcc --version output typically looks like
# gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
# Copyright (C) 2013 Free Software Foundation, Inc.
# This is free software; see the source for copying conditions. There is NO
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
# Check that this is likely to be GCC.
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null
# 条件语句注释掉
# if test $? -ne 0; then
# { $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
# $as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
# { $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with --version was: "$COMPILER_VERSION"" >&5
# $as_echo "$as_me: The result from running with --version was: "$COMPILER_VERSION"" >&6;}
# as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
最后执行sh configure
终于成功:
====================================================A new configuration has been successfully created in
/Users/chenyuan/Workspaces/Openjdk/openjdk8/build/macosx-x86_64-normal-server-release
using default settings.
Configuration summary:
* Debug level: release
* JDK variant: normal
* JVM variants: server
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
Tools summary:
* Boot JDK: java version "1.8.0_162" Java(TM) SE Runtime Environment (build 1.8.0_162-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode) (at /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home)
* Toolchain: gcc (GNU Compiler Collection)
* C Compiler: Version 11.0.3 (at /usr/bin/gcc)
* C++ Compiler: Version 11.0.3 (at /usr/bin/g++)
Build performance summary:
* Cores to use: 4
* Memory limit: 16384 MB
问题三:include path for libstdc++ headers not found
clang: clangerror: include path for libstdc++ headers not found; pass "-stdlib=libc++" on the command line to use the libc++ standard library instead [-Werror,-Wstdlibcxx-not-found]: error: include path for libstdc++ headers not found; pass "-stdlib=libc++" on the command line to use the libc++ standard library instead [-Werror,-Wstdlibcxx-not-found]
make[6]: *** [../generated/adfiles/archDesc.o] Error 1
make[6]: *** Waiting for unfinished jobs....
make[6]: *** [../generated/adfiles/adlparse.o] Error 1
clang: error: include path for libstdc++ headers not found; pass "-stdlib=libc++" on the command line to use the libc++ standard library instead [-Werror,-Wstdlibcxx-not-found]
make[6]: *** [../generated/adfiles/arena.o] Error 1
make[5]: *** [ad_stuff] Error 2
make[4]: *** [product] Error 2
make[3]: *** [generic_build2] Error 2
make[2]: *** [product] Error 2
make[1]: *** [/Users/chenyuan/Workspaces/Openjdk/openjdk8/build/macosx-x86_64-normal-server-release/hotspot/_hotspot.timestamp] Error 2
make: *** [hotspot-only] Error 2
解决方法
原因:这个原因是Xcode升级到10以后就没有包含lstdc++库了。而 hotspot 居然还一直用着这个,于是编译器找不到 libstdc++ 的头文件就罢工了
解决办法:
打开:https://github.com/imkiwa/xcode-missing-libstdc- , clone 到本地,参考 install.sh 将文件链接或者复制到对应位置(慎重直接执行,请一定事先核对路径是否正确)!
问题四:fatal error: "iostream" file not found
/Users/chenyuan/Workspaces/Openjdk/openjdk8/hotspot/src/share/vm/adlc/archDesc.cpp:#include <iostream>/Users/chenyuan/Workspaces/Openjdk/openjdk8/hotspot/src/share/vm/adlc/adlc.hpp: ^~~~~~~~~~35:10:27
:
fatal error/Users/chenyuan/Workspaces/Openjdk/openjdk8/hotspot/src/share/vm/adlc/adlc.hpp: :35"iostream" file not found:
10: fatal error: "iostream" file not found
#include <iostream>
^~~~~~~~~~
#include <iostream>
^~~~~~~~~~
In file included from /Users/chenyuan/Workspaces/Openjdk/openjdk8/hotspot/src/share/vm/adlc/adlparse.cpp:27:
/Users/chenyuan/Workspaces/Openjdk/openjdk8/hotspot/src/share/vm/adlc/adlc.hpp:35:10: fatal error: "iostream" file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
make[6]: *** [../generated/adfiles/arena.o] Error 1
make[6]: *** Waiting for unfinished jobs....
解决方案
xcode-select --install
问题五:unknown argument: "-fpch-deps"
解决方案:
hotspot/make/bsd/makefiles/gcc.make
# Compiler warnings are treated as errorsifneq ($(COMPILER_WARNINGS_FATAL),false)
WARNINGS_ARE_ERRORS = -Werror
endif
这一段也要干掉,否则在后续编译中可能会出现clang: error: unknown argument: "-fpch-deps"
ifeq ($(USE_CLANG),) ifneq ($(CC_VER_MAJOR), 2)
DEPFLAGS += -fpch-deps
endif
endif
问题六:invalid argument ‘-std=gnu++98’ not allowed with ‘C’
Making signal interposition lib...error: invalid argument "-std=gnu++98" not allowed with "C"
make[6]: *** [libjsig.dylib] Error 1
解决方案
if test "x$TOOLCHAIN_TYPE" = xsolstudio; then if test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
fi
elif test "x$TOOLCHAIN_TYPE" = xxlc; then
LDFLAGS_JDK="${LDFLAGS_JDK} -q64 -brtl -bnolibpath -liconv -bexpall"
CFLAGS_JDK="${CFLAGS_JDK} -qchars=signed -q64 -qfullpath -qsaveopt"
CXXFLAGS_JDK="${CXXFLAGS_JDK} -qchars=signed -q64 -qfullpath -qsaveopt"
elif test "x$TOOLCHAIN_TYPE" = xgcc; then
LEGACY_EXTRA_CFLAGS="$LEGACY_EXTRA_CFLAGS -fstack-protector"
LEGACY_EXTRA_CXXFLAGS="$LEGACY_EXTRA_CXXFLAGS -fstack-protector"
if test "x$OPENJDK_TARGET_OS" != xmacosx; then
LDFLAGS_JDK="$LDFLAGS_JDK -Wl,-z,relro"
LEGACY_EXTRA_LDFLAGS="$LEGACY_EXTRA_LDFLAGS -Wl,-z,relro"
fi
# CXXSTD_CXXFLAG="-std=gnu++98" # 注释掉这行
参考地址
- https://zhuanlan.zhihu.com/p/50220757
- https://www.jianshu.com/p/d9a1e1072f37
- https://www.cnblogs.com/zhengshuangxi/p/11063938.html
- https://juejin.im/entry/5a6c36af6fb9a01cb64f05b8
- https://www.zhoujunwen.com/2019/building-openjdk-8-on-mac-osx-catalina-10-15
- https://www.cnblogs.com/micrari/p/7018474.html
- https://rqsir.github.io/2019/04/19/openjdk-8-使用Clion调试源码/
如果大家喜欢我的文章,可以关注个人订阅号。欢迎随时留言、交流。如果想加入微信群的话一起讨论的话,请加管理员简栈文化-小助手(lastpass4u),他会拉你们进群。
以上是 深夜里安静的编译一个OpenJDK8,坑太多 的全部内容, 来源链接: utcz.com/z/517892.html