YouTip LogoYouTip

C Environment Setup

C Environment Setup

If you want to set up a C language environment, you need to ensure that you have the following two types of software available on your computer: a text editor and a C compiler.

Files created by an editor are usually called source files. Source files contain the program's source code.

Source files for C programs typically use the .c extension.

Before you start programming, make sure you have a text editor and enough experience to write a computer program, then save it in a file, compile it, and execute it.

  • Visual Studio Code: Although it is a general-purpose text editor, it has many plugins supporting C/C++ development, making it a popular choice. By installing the C/C++ plugin and adjusting settings, you can turn it into a good C language development environment.
    Installation tutorial:
    Download address: https://code.visualstudio.com/
  • Sublime Text: Sublime Text is a lightweight, fast, and highly customizable text editor with many plugins supporting C language development. It has powerful code editing features and keyboard shortcuts that make coding more efficient.
    Download address: https://www.sublimetext.com/
  • Atom: Atom is an open-source text editor developed by GitHub. It has many plugins and themes that can be customized to create a suitable environment for C language development.
    Download address: https://atom-editor.cc/
  • Vim and Emacs: These are traditional text editors with powerful editing capabilities and high customizability. They are very powerful for proficient users and have many plugins and configurations to support C language development.
  • Eclipse: Eclipse is another powerful integrated development environment. Although it was originally designed for Java development, by installing the C/C++ plugin, it can support C language development.

The source code written in source files is human-readable source. It needs to be "compiled" into machine language so that the CPU can execute the program according to the given instructions.

A C language compiler is used to compile source code into a final executable program. It is assumed here that you already have a basic understanding of programming language compilers.

The most commonly used freely available compiler is GNU's C/C++ compiler. If you are using HP or Solaris, you can use the compiler provided by your respective operating system.

The following sections will guide you on how to install GNU's C/C++ compiler on different operating systems. Both C and C++ are mentioned here mainly because GNU's gcc compiler is suitable for both C and C++ programming languages.


Installation on UNIX/Linux

If you are using Linux or UNIX, please use the following command in the command line to check if GCC is installed on your system:

$ gcc -v

If the GNU compiler is already installed on your computer, the following message will be displayed:

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, please follow the detailed instructions on http://gcc.gnu.org/install/ to install GCC.

This tutorial is written based on Linux, and all given examples have been compiled on a Cent OS Linux system.


Installation on Mac OS

If you are using Mac OS X, the fastest way to get GCC is to download the Xcode development environment from Apple's website and follow the installation instructions. Once Xcode is installed, you will be able to use the GNU compiler.

Xcode can currently be downloaded from developer.apple.com/technologies/tools/.

Installation on Windows

Cygwin

Cygwin is a software package that emulates a Unix/Linux environment on the Windows operating system, allowing users to use Unix-like tools and applications on Windows.

Cygwin works by providing a set of DLLs (Dynamic Link Libraries) that act as a bridge between the Unix system call layer and the Windows kernel, enabling Unix programs to run on the Windows system.

Cygwin Official Website: https://www.cygwin.com/.

Download the installer from the official website:

Image 1

After the download is complete, double-click the downloaded file:

Image 2

Next, you can keep clicking Next:

Image 3Image 4

Here we can add NetEase open-source mirror or Alibaba Cloud mirror https://mirrors.aliyun.com/cygwin/:

Image 5

After installation is complete, an icon will be generated on the desktop:

Image 6

Double-click the icon to enter the command-line interface. Enter the command cygcheck -c cygwin to view the current version information of Cygwin:

Image 7

Next, we install the gcc/g++ compilation environment. In the command line, navigate to the directory containing setup-x86_64.exe and 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 is complete, enter the Cygwin64 terminal. Enter the command gcc --version to view the version information.

MinGW-w64

To install GCC on Windows, you need to install MinGW-w64.

MinGW-w64 is an open-source project that provides a complete GCC toolchain for Windows systems, supporting the compilation of both 32-bit and 64-bit Windows applications.

Visit the MinGW-w64 homepage mingw-w64.org, go to the MinGW download page https://www.mingw-w64.org/downloads/, and download the latest version of the MinGW-w64 installer.

The MinGW-w64 download details page contains many packages integrating MinGW-w64 and specific tools:

Image 8

We only need to install MinGW-w64, so just download MinGW-w64. Click the "SourceForge" hyperlink in the red box to go to the MinGW-w64 download page on SourceForge.

Download MinGW-w64 on SourceForge: https://sourceforge.net/projects/mingw-w64/files/

There are also pre-compiled binary packages on Github: https://github.com/niXman/mingw-builds-binaries/releases

Image 9

You can download the installer for a specific system:

Image 10

This type of installation may encounter network connection errors, so we can directly download sjlj (stable, supports both 64-bit and 32-bit):

After downloading, extract it. Inside the bin directory, you can find g++.exe or gcc.exe:

Image 11

When installing MinGW, you should at least install gcc-core, gcc-g++, binutils, and MinGW runtime, but typically more items are installed.

Add the bin subdirectory of your installed MinGW to your system's PATH environment variable, so that you can specify these tools by their simple names from the command line.

Image 12

When the installation is complete, you can run gcc, g++, ar, ranlib, dlltool, and other GNU tools from the Windows command line.

← Os UtimeOs Unlink β†’