Maybe this is a problem with the path folder, if any directory in the path has a space or a special charactere, the gbd may have problem to build the archive.
If this is not the case, maybe the debugger is expecting you to inform the flags to the tasks, you can do it, in the tasks.json in the .vscode folder, in the arguments part. For exemple, if you are using math.h and lpthread.h you must have something like that in the args:
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-lm",
"-lpthread"
],