0

enter image description here

Cannot run C code in VS Code. C/C++, compiler extensions are all installed, even minGW is installed properly and added environmental variable. same error is occurring when compiling using terminal.

rioV8
  • 24,506
  • 3
  • 32
  • 49
Naveen Kumar
  • 65
  • 1
  • 5
  • 10
    Don’t use spaces in file names. The extensions don’t seem to like them – Sami Kuhmonen Jan 06 '22 at 12:26
  • That's the right answer –  Jan 06 '22 at 12:29
  • You are trying to compile the three files "hello", "world.c", and "world", and write the result in "hello". Either quote your file names, or don't use spaces in them. Most people choose the latter. (I would recommend that you locate a beginner's introduction to terminal use.) – molbdnilo Jan 06 '22 at 12:32

1 Answers1

0

As mentioned in the comments to the question by @SamiKuhmonen the solution is to avoid naming source files with spaces in them. It appears the VSCode extension does not properly handle files named with spaces in them.

drescherjm
  • 10,365
  • 5
  • 44
  • 64
Naveen Kumar
  • 65
  • 1
  • 5
  • has nothing to do with the extension, Like Sami comments **never use spaces** in filenames – rioV8 Jan 06 '22 at 12:35
  • 1
    Don't post "thank you" comments as an answer. – Jabberwocky Jan 06 '22 at 12:38
  • 1
    @Jabberwocky: It is acceptable however to copy a comment to an answer, like it's done here (space character in filename). You can't accept a comment, but you can accept this answer. And per the usual attribution rules, it's also correct to acknowledge SamiKuhmonen. – MSalters Jan 06 '22 at 13:00
  • It's best to never use a space in the path or file name in c or c++. The reason is both are compiled using the shell or command line where the space character separates different arguments. To get around this you need to quote the path when spaces are used however as you see not all build tools will handle that automatically and properly for you so its best to avoid the problem in the first place. – drescherjm Jan 06 '22 at 14:11
  • 2
    @rioV8 I'd argue that the extension is broken or misconfigured. We don't use spaces only because many tools don't handle them properly, the popularity of those tools doesn't make them not broken in this regard. – HolyBlackCat Jan 06 '22 at 15:11
  • @rioV8 - Note that the main IDE for Windows, Visual Studio (without "Code"), has always handled filenames with spaces correctly. It is pretty silly to introduce a new system that doesn't. – BoP Jan 06 '22 at 15:46
  • @BoP Visual Studio calls the compiler with a `sys.exe` call and passes an array with arguments, VSC composes a terminal command, types this to `stdin` of the terminal process and now it is the shell to parse this command to individual arguments, if you have spaces in your filename it will result in different arguments. So to get by any problems it is wise to never use spaces in filenames. Why do you have a `.` in the filename, why could you not have a space here to? – rioV8 Jan 06 '22 at 16:42
  • @rioV8 the compiler in VS is cl.exe by default. There's no sys.exe – phuclv Jan 06 '22 at 16:45
  • @BoP VS Code is a **text editor** and not IDE so obviously anything wrong would be with the extension and not VS Code. It's also possible that the OP is using the wrong shell – phuclv Jan 06 '22 at 16:46
  • @phuclv I don't know the exact C system call, it is something like `exec()` to start a new process – rioV8 Jan 06 '22 at 16:47
  • @rioV8 it has nothing to do with the system call. Windows APIs can run exe files with spaces in path without problem – phuclv Jan 06 '22 at 16:47
  • @phuclv That is because you pass an array with pre-parsed arguments to the `exec()` call with the parh to the executable as argument 1 or separate argument to `exec()` – rioV8 Jan 06 '22 at 16:49
  • @rioV8 there's no `exec` in Windows. Please stop assuming everything is working the Unix way. And it's the extension's developer who wrote it wrongly, not me – phuclv Jan 07 '22 at 04:25
  • @phuclv In Unix the name is `execvp` (and the likes) and in Windows the name is a bit different but behaves the same: https://stackoverflow.com/a/389352/9938317 – rioV8 Jan 07 '22 at 04:57
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/240811/discussion-between-phuclv-and-riov8). – phuclv Jan 07 '22 at 05:12