What is the version of your g++ compiler?
Per https://pytorch.org/tutorials/advanced/cpp_extension.html: 36

Due to ABI versioning issues, the compiler you use to build your C++ extension must be  ABI-compatible  with the compiler PyTorch was built with. In practice, this means that you must use GCC version 4.9 and above on Linux. For Ubuntu 16.04 and other more-recent Linux distributions, this should be the default compiler already. On MacOS, you must use clang (which does not have any ABI versioning issues). In the worst case, you can build PyTorch from source with your compiler and then build the extension with that same compiler.