Search code examples
c++visual-studio-code

VS code cannot compile mutiple C++ files(WSL)


I just started to setup my VS Code in WSL. I followed by the instruction from GCC on Windows subsystem for Linux. Most of the work is done, there is only one issue. For this part:

Modifying tasks.json

You can modify your tasks.json to build multiple C++ files by using an argument like ${workspaceFolder}/*.cpp instead of ${file}. You can also modify the output filename by replacing ${fileDirname}/${fileBasenameNoExtension} with a hard-coded filename (for example 'helloworld.out').

I want to compile multiple cpp files, but the method provides from above ${workspaceFolder}/*.cpp instead of ${file} doesn't work for me. After I replaced it, the g++ seems like recognize the *.cpp as a file so it can't find it.

This is what the terminal shows.

g++: error: /.../.../*.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated.
The terminal process terminated with exit code: 1

Solution

  • I find out the problem is on the name of my folder. There is a space in my folder name, so change the name of the folder solved this problem. It is really not a good habit to use space. But if you continue to want to use a name that contains space, do "\"${workspaceFolder}\"/.cpp" instead of "${workspaceFolder}/.cpp".