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/
collect2: fatal error: ld terminated with signal 9 [Killed]
compilation terminated.
make[2]: *** [caffe2/CMakeFiles/torch_cpu.dir/build.make:19257: lib/] Error 1
make[2]: *** Deleting file 'lib/'
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 "", line 818, in <module>
  File "", line 315, in build_deps
  File "/home/pytorch/pytorch/tools/", line 58, in build_caffe2
  File "/home/pytorch/pytorch/tools/setup_helpers/", line 345, in build, my_env)
  File "/home/pytorch/pytorch/tools/setup_helpers/", line 140, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "/usr/lib/python3.8/", 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