Because I want to use C++20 standard, I need to use GCC12, but the default compiler of Ubuntu20 is GCC9, so I have to compile and install a GCC trunk by myself.
I didn’t expect to have so many problems doing something that sounds so simple, so I’ll write a little bit of text to document it.
Download source code
1
|
git clone https://github.com/gcc-mirror/gcc.git
|
1
2
|
cd gcc
./contrib/download_prerequisites
|
Compile
1
2
3
4
5
|
mkdir build && cd build
../configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --enable-checking=release --enable-languages=c,c++ --disable-multilib
make -j8
|
Wait patiently for the compilation to complete, depending on the performance of the machine.
Installation
Problems encountered
After installing gcc, I don’t know why it reports an error when compiling LLVM.
1
|
/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found
|
Using strings /lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX
you can see that there is indeed no GLIBCXX_3.4.30
. Using ls -al /lib/x86_64-linux-gnu/libstdc++.so.6
you can see that this is a soft link
1
|
lrwxrwxrwx 1 root root 36 1月 1 13:44 libstdc++.so.6 -> libstdc++.so.6.29
|
Obviously this is still an old version of libstdc++
, and I’m not sure why it’s doing this -_-
The solution is straightforward, just re-link libstdc++.so.6
to our newly compiled version: libstdc++.so.6
.
1
2
|
unlink
ln -s /usr/local/lib64/libstdc++.so.6.0.30 /lib/x86_64-linux-gnu/libstdc++.so.6
|