How to fix ccache error when building OpenJDK from source
Published:
When compiling OpenJDK from source and have ccache enabled, we might get the following error:
configure: Using default toolchain gcc (GNU Compiler Collection)
checking for gcc... /usr/lib64/ccache/gcc
checking resolved symbolic links for CC... /usr/bin/ccache
configure: Please use --enable-ccache instead of providing a wrapped compiler.
configure: error: /usr/lib64/ccache/gcc is a symbolic link to ccache. This is not supported.
configure exiting with result code 1
This usually happens when the gcc found in your PATH is not the actual GCC binary, but a ccache wrapper:
$ which gcc
/usr/lib64/ccache/gcc
$ ll /usr/lib64/ccache/gcc
lrwxrwxrwx. 1 root root 16 May 12 15:27 /usr/lib64/ccache/gcc -> ../../bin/ccache
In this case, /usr/lib64/ccache/gcc is a symbolic link to the ccache executable. OpenJDK’s build system does not support passing a wrapped compiler directly.
A possible solution to this without manipulating the system files is to set the CC and CXX env variables with the right location for the C/C++ binaries:
bash configure \
CC=/usr/bin/gcc \
CXX=/usr/bin/g++ \
--with-boot-jdk=$JAVA_HOME \
--with-jtreg=$JTREG_HOME
Furthermore, we can also enable ccache with the --enable-ccache in combination with the CC and CXX env variables:
bash configure \
CC=/usr/bin/gcc \
CXX=/usr/bin/g++ \
--enable-ccache \
--with-boot-jdk=$JAVA_HOME \
--with-jtreg=$JTREG_HOME