📜  c++ 14 for sublime windows build system - C++ (1)

📅  最后修改于: 2023-12-03 15:13:53.810000             🧑  作者: Mango

C++ 14 for Sublime Windows Build System

Sublime Text is a popular text editor used by many programmers. It is highly extensible and customizable, allowing users to tailor the editor to their individual use cases. One of the key features of Sublime is its build system, which allows users to execute code and view output within the editor itself.

When it comes to C++ development, Sublime supports a range of build systems for compiling and running code. In this article, we will focus on the C++ 14 build system for Sublime on Windows.

Installation

To use the C++ 14 build system for Sublime on Windows, you will need to first install the MinGW-w64 toolchain. This toolchain provides the GCC compiler and other necessary tools for compiling C++ code.

To install MinGW-w64, follow these steps:

  1. Download the latest version of MinGW-w64 from the official website: https://sourceforge.net/projects/mingw-w64/

  2. Run the installer and select the following options:

    • Architecture: x86_64
    • Threads: posix
    • Exception: seh
    • Build revision: the latest version available
  3. Select an installation directory of your choice.

  4. Click "Install" to begin the installation process.

Once MinGW-w64 is installed, you can set up the C++ 14 build system in Sublime.

Setting Up the Build System

To set up the C++ 14 build system in Sublime, follow these steps:

  1. Open Sublime Text and create a new file.

  2. Copy and paste the following code into the file:

    {
        "cmd": ["g++", "-std=c++14", "${file}", "-o", "${file_path}/${file_base_name}"],
        "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
        "working_dir": "${file_path}",
        "selector": "source.c, source.c++",
        "variants":
        [
            {
                "name": "Run",
                "cmd": ["start", "${file_path}/${file_base_name}.exe"]
            }
        ]
    }
    
  3. Save the file with the name "C++ 14.sublime-build" in the following directory:

    %USERPROFILE%\AppData\Roaming\Sublime Text 3\Packages\User
    

    Note: If you are using a different version of Sublime, replace "Sublime Text 3" with the appropriate version number.

  4. Restart Sublime Text to apply the changes.

You should now be able to use the C++ 14 build system to compile and run C++ code in Sublime.

Usage

To use the C++ 14 build system in Sublime, follow these steps:

  1. Open a C++ file in Sublime.

  2. Press Ctrl + B to build the file.

  3. If there are no errors, a new window will open showing the output of the program.

    Note: If there are errors, the output will show the error messages and their locations in the code.

  4. To run the program, select the "Run" variant from the build menu (Tools -> Build With).

    Note: If the program takes input, you can provide it in the output window before running the program.

Conclusion

The C++ 14 build system for Sublime on Windows provides a fast and convenient way to compile and run C++ code within the editor. By following the steps outlined in this article, you should be able to set up the build system and start developing in no time. Happy coding!