Build failing on WSL2 Ubuntu 20.04

I’m not using ninja. Building from source always fails with a similar reason on WSL2 Ubuntu 20.04.
On Ubuntu 20.04 (non-WSL, dual-boot OS), I had run into similar issues but I removed ninja & then install succeeded. However, I haven’t had such luck on WSL2 Ubuntu 20.04.

[ 79%] Linking CXX shared library ../lib/libtorch_cpu.so
collect2: fatal error: ld terminated with signal 9 [Killed]
compilation terminated.
make[2]: *** [caffe2/CMakeFiles/torch_cpu.dir/build.make:19257: lib/libtorch_cpu.so] Error 1
make[2]: *** Deleting file 'lib/libtorch_cpu.so'
make[1]: *** [CMakeFiles/Makefile2:11850: caffe2/CMakeFiles/torch_cpu.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
Traceback (most recent call last):
  File "setup.py", line 818, in <module>
    build_deps()
  File "setup.py", line 315, in build_deps
    build_caffe2(version=version,
  File "/home/pytorch/pytorch/tools/build_pytorch_libs.py", line 58, in build_caffe2
    cmake.build(my_env)
  File "/home/pytorch/pytorch/tools/setup_helpers/cmake.py", line 345, in build
    self.run(build_args, my_env)
  File "/home/pytorch/pytorch/tools/setup_helpers/cmake.py", line 140, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Debug', '--', '-j', '8']' returned non-zero exit status 2.

Hey! did you find a solution to this?

For WSL2, the issue was resolved by setting up a .wslconfig file & assigning specific amount of memory to WSL2. I allocated 8 GB & it worked. I also set the MAX_JOBS environment variable to a low value.

1 Like