Cpp Environment Setup
If you want to set up a C++ programming environment, you need to ensure that your computer has the following two software components available: a text editor and a C++ compiler.
Files created using a text editor are commonly referred to as source files, which contain the program's source code.
C++ source files typically use the extensions `.cpp`, `.cp`, or `.c`.
Before starting to program, make sure you have a text editor and sufficient experience writing a computer program, saving it to a file, compiling it, and executing it.
* **Visual Studio Code**: Although it is a general-purpose text editor, it offers many plugins supporting C/C++ development, making it a popular choice. By installing the C/C++ extension and adjusting settings, you can configure it into an excellent C development environment.
Installation tutorial: [
Download link: [https://code.visualstudio.com/](https://code.visualstudio.com/)
* Visual Studio: A comprehensive Windows IDE for .NET and C++ developers, suitable for building web, cloud, desktop, mobile applications, services, and games.
Download link: [https://visualstudio.microsoft.com/zh-hans/downloads/](https://visualstudio.microsoft.com/zh-hans/downloads/).
* **Vim** and **Emacs**: These are traditional text editors with powerful editing capabilities and high customizability. They are extremely powerful for experienced users, and numerous plugins and configurations support C development.
* **Eclipse**: Eclipse is another powerful integrated development environment (IDE). Though originally designed for Java development, it supports C development after installing the C/C++ plugin.
### Additional Related Tools
AI Development Environment
Source code written in source files is human-readable. It must be "compiled" into machine language so the CPU can execute the program according to the given instructions.
A C++ compiler is used to compile source code into the final executable program.
Most C++ compilers do not strictly enforce source file extensions; however, if no extension is specified, `.cpp` is used by default.
The most commonly used freely available compiler is GNUβs C/C++ compiler. If you are using HP or Solaris, you may use the respective compilers provided by those operating systems.
The following sections will guide you through installing GNUβs C/C++ compiler on different operating systems. We refer to both C and C++ here because GNUβs `gcc` compiler supports both C and C++ programming languages.
* * *
## Installation on UNIX/Linux
If you are using **Linux or UNIX**, run the following command in the terminal to check whether GCC is installed on your system:
$ g++ -v
If GNU Compiler Collection (GCC) is already installed on your computer, the following message will appear:
Using built-in specs.Target: i386-redhat-linux Configured with: ../configure --prefix=/usr .......Thread model: posix gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)
If GCC is not installed, follow the detailed installation instructions at [https://gcc.gnu.org/install/](https://gcc.gnu.org/install/).
* * *
## Installation on Mac OS X
If you are using Mac OS X, the quickest way to obtain GCC is to download the Xcode development environment from Appleβs website and follow the installation instructions. Once Xcode is installed, you can use the GNU compiler.
Xcode is currently available for download at [https://developer.apple.com/download](https://developer.apple.com/download), requiring sign-in with an Apple ID.
* * *
## Installation on Windows
### Cygwin
Cygwin is a software package that simulates a Unix/Linux environment on the Windows operating system, enabling users to utilize Unix-like tools and applications on Windows.
Cygwin provides a set of DLLs (Dynamic Link Libraries) acting as a bridge between Unix system calls and the Windows kernel, allowing Unix programs to run on Windows.
**Cygwin official website: https://www.cygwin.com/**.
Download the installer from the official website:
!(#)
After downloading, double-click the downloaded file:
!(#)
Then keep clicking Next:
!(#)
!(#)
Here, we can add mirrors such as NetEase Open Source Mirror or Alibaba Cloud Mirror: https://mirrors.aliyun.com/cygwin/:
!(#)
After installation completes, an icon appears on the desktop:
!(#)
Double-click the icon to enter the command-line interface, then type the command `cygcheck -c cygwin` to view the current Cygwin version information:
!(#)
Next, install the `gcc`/`g++` compilation environment. In the command line, navigate to the directory containing `setup-x86_64.exe`, then execute:
setup-x86_64.exe -q -P wget -P gcc-g++ -P make -P diffutils -P libmpfr-devel -P libgmp-devel -P libmpc-devel
After installation completes, launch the Cygwin64 Terminal and run the command `gcc --version` to verify the version information.
### MinGW-w64
To install GCC on Windows, you need to install MinGW-w64.
MinGW-w64 is an open-source project providing a complete GCC toolchain for Windows, supporting compilation of both 32-bit and 64-bit Windows applications.
Visit the MinGW-w64 homepage at [mingw-w64.org](https://www.mingw-w64.org/) and go to the MinGW downloads page at [https://www.mingw-w64.org/downloads/](https://www.mingw-w64.org/downloads/) to download the latest MinGW-w64 installer.
> You can also download from GitHub: [https://github.com/niXman/mingw-builds-binaries/releases](https://github.com/niXman/mingw-builds-binaries/releases)
The MinGW-w64 download details page includes many bundled packages for MinGW-w64 and specific tools:
!(#)
We only need to install MinGW-w64, so just download MinGW-w64. Click the βSourceForgeβ hyperlink in the red box to navigate to the MinGW-w64 download page on SourceForge.
Download MinGW-w64 from SourceForge: [https://sourceforge.net/projects/mingw-w64/files/](https://sourceforge.net/projects/mingw-w64/files/)
!(#)
Scroll down the page and download the installer:
!(#)
This installation method may encounter network connection errors, so we can directly download the sjlj version (stable, supporting both 64-bit and 32-bit):
!(#)
After downloading, extract the archive. Inside the `bin` directory, youβll find `g++.exe` or `gcc.exe`:
!(#)
When installing MinGW, you must at least install `gcc-core`, `gcc-g++`, `binutils`, and the MinGW runtime; however, usually more components are installed.
Add the `bin` subdirectory of your MinGW installation to your **PATH** environment variable, allowing you to invoke these tools from the command line using simple names.
!(#)
After completing installation, you can run `gcc`, `g++`, `ar`, `ranlib`, `dlltool`, and other GNU tools from the Windows command line.
* * *
## Compiling Using Visual Studio (Graphical Interface)
1. Download and install (https://visualstudio.microsoft.com/zh-hans/downloads/).
!(#)
2. Launch Visual Studio Community.
3. Click File β New β Project.
!(#)
4. From the left-hand list, select Templates β Visual C++ β Win32 Console Application, and set the project name to MyFirstProgram.
!(#)
5. Click OK.
6. In the following window, click Next.
!(#)
7. In the pop-up window, select the Empty project option, then click Finish:
8. Right-click the Source Files folder and click Add β New Itemβ¦:
!(#)
9. Select C++ File, set the filename to main.cpp, then click Add:
!(#)
10. Copy the following code into main.cpp:
#include int main(){ std::cout << "Hello World!n"
YouTip