C/C++ Solved - How to use or set Clang/LLVM/GCC compilers on VS Code?

I couldn't find anything on google on how to configure VS code on FreeBSD to use clang/llvm/gcc.

I have clang/llvm and gcc installed on FreeBSD 13.1

I have installed this extension:

Which installs the following extension on VS code:


Every time I click on the compile "Play" button on VS Code I get this error:

Code:
[Running] cd "/home/user/" && g++ test.cpp -o test && "/home/user/"test2

/bin/sh: g++: not found

Note: I was able to compile an OpenCV test project which has a CMake file and VS Code can automatically recognize the CMake file and compile it using Clang/LLVM compiler, I use the "Build" button at the very bottom task bar on VS Code.

Its just that I cannot compile/build simple "C" code to use clang/llvm on VS Code by default when clicking on the "play button" which is located at the top right on VS Code.

Thanks for any advice.

EDIT:

I spent about 2 full days in figuring out how to get VS code to work as an IDE for c/c++ on FreeBSD 13.1

I am now able to compile OpenCV 4 projects using clang and debug using GDB on VS Code. I guess I will make a tutorial to help anyone who wants to do the same, I couldn't find much info in how all of this works on VS Code to make it into an IDE, but from my experience VS code makes it super easy to configure things and makes workflow easy and fast once understanding how VS code can be configured.

Here is a good tutorial on how get the debugger working on VS code:
(Note: I was not able to get the debugger working using the C/C++ Microsoft VS Code Extension, I had to install the WebFreak Native Debugger Extension to get the native GDB Debugger to work on VS code)

I haven't found a good tutorial on how to get clang or GCC compilers working on VS code for FreeBSD, will make a tutorial on that later. Since they need to be manually configured on VS code.
Here is a tutorial on the concept to get c/c++ compilers to work on VS Code:

Here is the user space task.json which works for me on FreeBSD 13.1 to get clang and gcc compilers to work:

Code:
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Clang++ [OpenCV]",
      "type": "shell",
      "command": "/usr/bin/clang++",
      "includePath": [
        "${workspaceFolder}/**",
        "/usr/local/include/opencv4/**"
    ],
      "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}", 
        "$(pkg-config", "--cflags", "--libs", "opencv4)"
      ],
      "options": {
        "cwd": "${workspaceFolder}"
      },
      "problemMatcher": [],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    },
    {
      "label": "Clang++ [No Parameters]",
      "type": "shell",
      "command": "/usr/bin/clang++",
      "includePath": [
        "${workspaceFolder}/**",
    ],
      "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"],
      "options": {
        "cwd": "${workspaceFolder}"
      },
      "problemMatcher": [],
      "group": {
        "kind": "build",
        "isDefault": false
      }
    },
    {
      "label": "g++11 [No Parameters]",
      "type": "shell",
      "command": "/usr/local/bin/g++11",
      "args": ["-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],
      "options": {
        "cwd": "${workspaceFolder}"
      },
      "problemMatcher": [],
      "group": {
        "kind": "build",
        "isDefault": false
      }    
    }
  ]
}
 
Last edited:
Top