Search code examples
c++sublimetext3build-system

Sublime Text C++ Build System


I use the following compiler settings to compile my C++ code:

g++ -Wall -Wextra -O2 -fwrapv -Wfloat-equal -Wconversion -std=c++17 A.cpp

But I am not sure how to setup the build system for the purpose, nor I want to try myself! I doubt that I may mess up the configuration (because I did once).

So I need help to configure my build system for the above compiler settings. How can I do that?


Solution

  • This build system works in my machine, basically its the default C++ build system with the extra options,

    {
        "shell_cmd": "g++ -Wall -Wextra -O2 -fwrapv -Wfloat-equal -Wconversion -std=c++17 \"${file}\" -o \"${file_path}/${file_base_name}\"",
        "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
        "working_dir": "${file_path}",
        "selector": "source.c++",
    
        "variants":
        [
            {
                "name": "Run",
                "shell_cmd": "g++ -Wall -Wextra -O2 -fwrapv -Wfloat-equal -Wconversion -std=c++17 \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
            }
        ]
    }
    
    

    You can place it in /Users/{user}/Library/Application Support/Sublime Text 3/Packages/User directory for MacOs, C:\Users\{user}\AppData\Roaming\Sublime Text 3\Packages\User in Windows or ~/.config/sublime-text-3/Packages/User in Linux.
    You can call the file something like C++17.sublime-build to differentiate it from the default build system.