C++ is a powerful programming language that’s widely used in software development. If you’re new to C++ and want to get started with programming, you’ll need to set up a development environment on your computer.
In this article, we’ll show you how to install C++ Sublime Text and MinGW on Windows.
Sublime Text is a popular text editor that’s used by many programmers because of its speed, simplicity, and ease of use.
MinGW is a set of tools that allow you to compile and run C++ programs on Windows. By installing C++ Sublime Text and MinGW, you’ll have everything you need to start writing and running C++ code on your Windows computer.
Install Sublime Text
The first step in setting up your C++ development environment is to install Sublime Text. You can download the latest version of Sublime Text from the official website.
Once the download is complete, follow these steps to install Sublime Text:
- Double-click the downloaded file to start the installation process.
- Follow the on-screen instructions to complete the installation.
- Once the installation is complete, launch Sublime Text from the Start menu.
Step 1: Install Package Control
Package Control is a package manager for Sublime Text that allows you to easily install and manage plugins. To install Package Control, follow these steps:
- Open Sublime Text.
- Press Ctrl + ` to open the console.
- Copy and paste the following code into the console:
import urllib.request,os; pf = ‘Package Control.sublime-package’; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), ‘wb’).write(urllib.request.urlopen( ‘http://packagecontrol.io/‘ + pf.replace(‘ ‘,’%20’)).read())
- Press Enter to run the code.
- Wait for Package Control to install.
Step 2: Install C++ Build System
Now that you have Package Control installed, you can use it to install the C++ build system. The C++ build system is a plugin that allows you to build and run C++ programs from within Sublime Text.
To install the C++ build system, follow these steps:
- Open Sublime Text.
- Press Ctrl + Shift + P to open the Command Palette.
- Type “Package Control: Install Package” and press Enter.
- Type “C++ Build System” and press Enter.
- Wait for the C++ build system to install.
Install MinGW
The final step in setting up your C++ development environment is to install MinGW. MinGW is a set of tools that allows you to compile and run C++ programs on Windows.
To install MinGW, follow these steps:
- Download the latest version of MinGW from the official website.
- Double-click the downloaded file to start the installation process.
- Follow the on-screen instructions to complete the installation.
- When prompted to select the components to install, select “mingw32-base” and “mingw32-gcc-g++”.
- Once the installation is complete, add the MinGW bin folder to your system PATH environment variable. To do this, follow these steps:
a. Open the Control Panel.
b. Click on System and Security.
c. Click on System.
d. Click on Advanced system settings.
e. Click on the Environment Variables button.
f. Under “System variables”, scroll down and select the “Path” variable.
g. Click on Edit.
Configure Sublime Text to Use MinGW
Now that you have installed MinGW and Sublime Text, it is time to configure Sublime Text to use the MinGW compiler. Here are the steps:
- Open Sublime Text and click on “Tools” from the menu bar. Then, select “Build System” and click on “New Build System”.
- In the new build system file, paste the following code:
{ "cmd": ["gcc", "$file_name", "-o", "${file_base_name}.exe", "&&", "${file_base_name}.exe"], "selector": "source.c", "shell": true, "working_dir": "${file_path}" }
- Save the file with a name that will remind you that this build system is for C++ code. For example, you could name it “C++_MinGW.sublime-build”.
Compile and Run Your C++ Code
Now that Sublime Text is configured to use the MinGW compiler, you can compile and run your C++ code.
- Open the C++ file that you want to compile and run in Sublime Text.
- Click on “Tools” in the menu bar and select “Build System”. Then, select “C++_MinGW” (or whatever name you gave to the build system file you created in Step 4).
- Press “Ctrl + B” to build the code.
- If the code compiles without errors, a new console window will appear with the output of your code.
Congratulations, you have successfully installed Sublime Text and MinGW on your Windows computer and compiled your C++ code using Sublime Text.