Compiling error with tools/build_libtorch.py

Hi, I’m trying to build libtorch but met with compiling errors. My steps were like:

git clone GitHub - pytorch/pytorch: Tensors and Dynamic neural networks in Python with strong GPU acceleration
cd pytorch

git checkout v2.2.1 (tried with latest main and rel 2.2.1, got same error)

git submodule init
git submodule update --init --recursive
python tools/build_libtorch.py

and the error message is

/home/f/anaconda3/envs/libt-build/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/stl_algobase.h:431:30: error: argument 1 null where non-null expected [-Werror=nonnull]
431 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
| ~^~~~~~~~~~~~~~~~~~~~~~~

The GCC is v12.3.

Could someone help to diagnose how to use the script to build libtorch? Many thanks.

The issue seems to be related to this one and I guess it might be caused by GCC 12.x. You could update the issue with your reproducer.