I am new to VS code. I have configured it using Clang on macOS using the provided [VS code documentation] (https://code.visualstudio.com/docs/cpp/config-clang-mac)
It works, I can build and debug. Great!
My question is: how do I configure VS Code to build in Release mode? I don't seem to be able to find any info in the documentation or a tutorial on how to do it
In case it helps, this is the way tasks.json looks right now
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"-v",
"${file}",
"${workspaceFolder}/source/*.cpp",
"${workspaceFolder}/FFTreal/*.cpp",
"-I.",
"-L",
"${workspaceFolder}/BassLibrary",
"-lbass",
"-o",
"${workspaceFolder}/final.out",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Any idea? Thanks!
Sorry, for the last answer...
So first of all, I need to claim that I'm not really familiar to Clang Family, but I did some research and found that there are two special groups out in tasks.json
which VSCode provides: Build and Test. So, I guess that we need to build it in release mode manually where again I don't have any confidence on me...
I found that you can build your Clang scripts using CMake. CMake is simply a builder tool to help you reassemble your whole code, including libraries, dependencies, modules etc.
So, I'm not sure if that'll be possible but you can change your tasks.json
configuration from Clang++ to CMake, maybe?
First of all, for a quick answer, I edited your tasks.json
snippet to this:
{
"tasks": [
{
"label": "cmake init",
"type": "shell",
"options": {
"cwd": "${workspaceRoot}"
},
"command": "/path/to/cmake",
"args": [
"-S",
"${cwd}",
"-B",
"${cwd}/build"
],
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "cmake release builder",
"type": "shell",
"options": {
"cwd": "${workspaceRoot}"
},
"command": "/path/to/cmake",
"args": [
"--build",
"${workspaceRoot}/build",
"--config",
"Release"
],
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
What it does is, basically CMake scans your project folder and create configuration files via the cmake init
task. After that, when you run cmake release builder
, the task will assume that you have a build folder - which you can change easily - and creates a compact executable file, in build/Release
.
But also, in order to use CMake, you need to create a CMakeLists.txt
file whose baseName is case-sensitive. So, I created a really simple CMake configuration file which you can add your source files manually, unfortunately, like this:
cmake_minimum_required(VERSION 3.13) # CMake version check
project(simple_example) # Create project "simple_example"
set(CMAKE_CXX_STANDARD 14) # Enable c++14 standard
set(SOURCE_FILES test.cpp add.cpp) # Append source files
# Add executable target with source files listed in SOURCE_FILES variable
add_executable(simple_example ${SOURCE_FILES})
Finally, to make this process REAL, you need to go Terminal > Run Build Task
in VSCode.
I'm not really sure that you can use Clang compiler to build a whole application, like an .exe file in Windows. During the research, I focused a lot on the difference between compiler and builder which I recommend to look it up!
I hope that I used English in a comprehensible way and not made confused.