Cannot compile in Linux

When I try to compile in WSL2 I get:

samlef@DESKTOP-14FHLC1:~/git/hmipanel$ mbed-tools compile --clean --mbed-target NUCLEO_G474RE --toolchain GCC_ARM
Traceback (most recent call last):
File “/home/samlef/.local/bin/mbed-tools”, line 8, in
sys.exit(cli())
File “/home/samlef/.local/lib/python3.8/site-packages/click/core.py”, line 1157, in call
return self.main(*args, **kwargs)
File “/home/samlef/.local/lib/python3.8/site-packages/click/core.py”, line 1078, in main
rv = self.invoke(ctx)
File “/home/samlef/.local/lib/python3.8/site-packages/mbed_tools/cli/main.py”, line 38, in invoke
super().invoke(context)
File “/home/samlef/.local/lib/python3.8/site-packages/click/core.py”, line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/samlef/.local/lib/python3.8/site-packages/click/core.py”, line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/samlef/.local/lib/python3.8/site-packages/click/core.py”, line 783, in invoke
return __callback(*args, **kwargs)
File “/home/samlef/.local/lib/python3.8/site-packages/mbed_tools/cli/build.py”, line 98, in build
shutil.rmtree(build_tree)
File “/usr/lib/python3.8/shutil.py”, line 718, in rmtree
_rmtree_safe_fd(fd, path, onerror)
File “/usr/lib/python3.8/shutil.py”, line 675, in _rmtree_safe_fd
onerror(os.unlink, fullname, sys.exc_info())
File “/usr/lib/python3.8/shutil.py”, line 673, in _rmtree_safe_fd
os.unlink(entry.name, dir_fd=topfd)
PermissionError: [Errno 13] Permission denied: ‘.ninja_deps’

I think the reason here was that the build folder was created in a docker session and was root owned.

Possible solutions are:

  • Delete the build folder /cmake_build and compile again outside the docker
sudo rm -rf /cmake_build 
mbed-tools compile --mbed-target NUCLEO_G474RE --toolchain GCC_ARM
  • Claim acces rights with and rebuild:
sudo chown <username>:<username> -R cmake_build
mbed-tools compile --mbed-target NUCLEO_G474RE --toolchain GCC_ARM