Home > database >  Clang build an executrion file in vscode
Clang build an executrion file in vscode

Time:11-04

I've been searching whole internet but I can't find the solution for building my c project with clang compiler. I'm new to all this stuff and sorry for misunderstanding. I have default tasks.json file:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "clang   build active file",
            "command": "C:/Program Files/LLVM/bin/clang  ",
            "args": [
                "-std=c  17",
                "-stdlib=libc  ",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
  }

I can compile and this is what I've got compiled, 3 files:

enter image description here

I need to create executable somehow... Thanks for help.

CodePudding user response:

If you read the documentation (which is for MinGW but it's exactly the same for Clang for Windows), you need to explicitly add the .exe suffix to your output file.

So your "executable" file is the one named main, without any suffix or "extension".

You need to change your tasks.json file to add the .exe suffix:

"${fileDirname}/${fileBasenameNoExtension}.exe"
# Note the suffix here -------------------^^^^
  • Related