Readme-builds. HTML is pretty clear. Of course, even with readme-builds. HTML doesn’t mean there won’t be any problems. Therefore, this paper only aims at the problems encountered in the compilation process and the thinking summary of solving the problem;

Before you start, configure the environment variables:

vi ~/.bash_profile
Copy the code

At the bottom of the.bash_profile file insert:

Export LANG=C export CC= GCC Export CXX=g++ # skip some of the strict syntax checks of clang, Export LFLAGS=' -xlinker -lstDC ++' # whether to use clang export USE_CLANG=false # Export LP64=1 # Export ALLOW_DOWNLOADS=true # ALLOW_DOWNLOADS=true I chose 2 export HOTSPOT_BUILD_JOBS=2 # whether to skip the comparison with the previous version export SKIP_COMPARE_IMAGES=true # Whether to use precompiled header files, Export USE_PRECOMPILED_HEADER=true # Whether to use incremental compilation Export INCREMENTAL_BUILD=true # Export BUILD_LANGTOOLS=true export BUILD_JAXP=true export BUILD_JAXWS=true export BUILD_CORBA=true export BUILD_HOTSPOT=true export BUILD_JDK=true # Compile version export SKIP_DEBUG_BUILD=true export SKIP_FASTDEBUG_BUILD=false export DEBUG_NAME=debug # Avoid sections like Javaws and browser Java plug-ins like build export BUILD_DEPLOY=false export BUILD_INSTALL=false unset JAVA_HOMECopy the code

After entering, execute the following command to make the changes take effect:

source ~/.bash_profile
Copy the code

Problems encountered:

Slowdebug contains the most extensive debugging information. Without this information, a lot of the execution may be optimized, and some variables may not be visible when we step through. So it is best to specify **slowdebug** as compilation level) :

bash ./configure - with - debug - level = slowdebug - with - the boot - JDK = / Library/Java/JavaVirtualMachines jdk1.7.0 _80. JDK/Contents/HomeCopy the code

Configure: error: GCC compiler is required

First error encountered:

Reason: Starting with XCode 4.2, Clang has replaced GCC as the default compiler for macOS: clang.llvm.org/get_started…

Do not want to change jdK9 or install old XCode:

If GCC is not available, install gcc4.9 instead (you can comment out the GCC compiler error code so that you do not need to install GCC and compile with clang). Do not install a compiler version higher than 5, because c++14 is enabled by default and the compiler will break.

The brew install [email protected]Copy the code

After installation, you need to point the installed GCC4.9 to the system’s default GCC:

Sudo ln -s /usr/local/cellar /[email protected]/4.9.4_1/bin/gcc-4.9 /usr/bin/gccsudo ln -s / usr/local/Cellar/[email protected]/4.9.4 _1 / bin/g + + 4.9 / usr/bin/g + +Copy the code

Ln: /usr/bin/gcc: Operation not permitted The MAC was enabled with SIP from El Capitan to improve system security and prevent third-party software from permitted system-level directories. Even the root user has permission restrictions for the following directories:

According to the tips on the official website, users are recommended to use the following paths instead:

/usr/local/bin = /usr/local/bin = /usr/local/bin = /usr/local/bin

Cellar/[email protected]/4.9.4_1/bin/gcc-4.9 /usr/local/bin/gcc sudo ln -s /usr/local/bin/gcc sudo ln -s /usr/local/bin/gcc sudo ln -s /usr/local/bin/gcc sudo ln -s Cellar/[email protected]/4.9.4_1/bin/g++-4.9 /usr/local/bin/g++ alias GCC ='/usr/local/bin/gcc' alias g++='/usr/local/bin/g++'Copy the code

Configure: error: Could not find freetype! Configure: error: Could not find freetype If you lack a font library, install a font library:

brew install freetype
Copy the code

After installing, run configure again, this time returning:

It means that the configuration is ok, but it is better to install ccache to speed up, fine, and then install ccache:

brew install ccache
Copy the code

Mysql > make all; mysql > make all;

Error: Ordered comparison between pointer and zero (‘char *’ and ‘int’)

This error is caused by a different compiler environment. The XCode compiler is LLVM, while OpenJDK8 uses GCC by default. So just change the code that reports this error from pointer>0 to pointer! =NULL, for example:

Just change base()>0 to base! = can be NULL

‘X11/ xlib. h’ file not found

I looked it up and I need to install XQuartz. See: support.apple.com/zh-cn/HT201…

After installation, you need to configure:

 ln -s /opt/X11/include/X11 /usr/local/include/X11
Copy the code

Then the compilation is complete:

Finally, verify the compiled JDK:

build/macosx-x86_64-normal-server-fastdebug/jdk/bin/java -version
Copy the code

If the following information is displayed, the compilation is successful: