Compile C program with gcc compiler in Windows 10



Compile C program with GCC compiler

The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. You can compile by using the GCC command in Windows 10 Bash on Ubuntu. GCC is a key component of the GNU toolchain and the standard compiler most Unix-like operating system. 

       C Programming Tutorials for Beginners

       Downloading Programming E-BOOK

Compile C program on windows 10


1. Enable Bash on Windows 10

If you don't know how to Enable/Activate Bash on Ubuntu on Windows 10, then check out our this tutorial Learn Stepwise to Enable Win 10 Subsystem for Windows 10.






2. Install gcc compiler in Windows 10 Bash

Enter the following command in your bash terminal to Install GCC compiler in Windows 10 Bash. Installation Guide for Windows.

                                         apt-get   install gcc           

Windows 10 Bash


After successfully the compiler is installed on your Windows 10 Bash. Type the following command to verify that gcc is installed: 
                                         which gcc

Example Outputs: 

                                        /usr/bin/gcc

How to find out the version of GCC compiler


                                       gcc   --version

Install gcc compiler in Windows  Bash




3. Write your first program on bash

Use any type of TEXT EDITORS such as vim or nano to create a C program called hello.c:

                             vim hello.c   or   nano hello.c

how write program on bash


Type your lines of  programming in command screen (example):




write program lines in text editor app

After writing your program, press ctrl+o and click on  Enter key to save your program. To quiet press Ctrl + x.





4. How Compile & Run Program

Compile hello.c  C program, and create a .exe (executable) file called hello, enter:

                                           gcc   hello.c   -o   hello       

To execute program first, enter: 


                                                         ./hello

 Output:


                                       hello world

gcc compiler Windows 10

Learn Stepwise to Enable Windows 10 Subsystem for Linux



Activate Windows 10 Subsystem for Linux

Microsoft built new infrastructure within windows - the Windows subsystem for Linux (WSL) - upon which we run a genuine Ubuntu user - mode image provided by Microsoft great partners over at Canonical, creators of Ubuntu Linux. The result that you can now run native Blash on Ubuntu on Windows.

          10 Basic Linux Commands for beginners

          Head First Java 2nd Edition [pdf] - E-BOOK


How to - Enable Windows 10's Ubuntu Bash Shell

Before we started, ensure that you've installed the Windows 10 Latest Update. This only works on the 64-bit Win 10

              C Programming Language Tutorials for Beginners
     
              Download Programming E-BOOKs 


Windows 10's Ubuntu Bash Shell

Step 1 - Enable/Activate Developer Mode

To enable/activate Developer Mode press the Windows Key and search For Developer Setting and click into the setting.

               Download Turbo C++ Program Compiler




For Developer Setting

Step 2 - Enable / Activate the Win Subsystem for Linux

To enable the Windows Subsystem for Linux (Beta), open the Control Panel, click Features and Programs or Programs and Features, and click on Turn Windows 10 Features On or Off in the sidebar programs. Enable the Windows Subsystem for Linux (Beta) option in the list here and click ok. After you do that, you'll need to reboot your system. After reboot, your system and Windows will install the new features.



Activate the Win Subsystem for Linux

Step 3 - Download and Install the Bash on Ubuntu on Windows 10

After your computer restarts, you've needed to Download and Install Bash for Windows. Then click on the Start Button (Press the Win Key), type bash, and press Enter key.

               Turbo C++ Software Problems Solution

               Software Installation Guide for Windows  

The first time you can run the bash.exe file, you'll be prompted to accept the terms of service. The command then will download Bash on Ubuntu on Windows 10 application from the Windows Store. You'll be asked to create a user account and password for use in the bash environment.


Bash on Ubuntu on Windows 10


If you'de like to automate the installation Bash instead, you can run the following command in a command prompt window. This will automatically agree to all prompts and set the default user root with no password.


lxrun /install /y   

Step 4 - Use Ubuntu's Bash Shell on Windows 10

You'll now have a full command-line shell based on Ubuntu. Because they're the same binaries, you can use Ubuntu's apt-get command to install software from Ubuntu's repositories. To open the Bash Shell, just open your Start Menu and Search for "bash" or "Ubuntu." You'll see a "Bash on Ubuntu on Windows 10" application.

Use Ubuntu's Bash Shell on Windows

If you're experienced using a Bash Shell on Linux, Mac OS X, or other platforms, you'll be right at home. You don't need to use sudo, as you're given a root shell. The "root" user on UNIX platforms has full system access, like the "Administrator" user on Windows 10. Your Windows file system is located at /mnt/c in the Bash Shell environment.


Use Ubuntu's Bash Shell on Windows

Use the same Linux terminal commands you'd use to get around. If you're used to the standard Windows Command Prompt with its DOS commands, here are a few basic commands on both Bash and Windows.



  • Change Directory - cd in Bash, cd or chdir in DOS
  • List Contents of Directory - ls in Bash, dir in DOS
  • Move or Rename a File - mv in Bash, move and rename in DOS
  • Click here to get more commands

It's important to remember that, unlike Windows, the Bash shell and Linux-imitating environment are case-sensitive. In order words, File.txt with a capital letter is different from file.txt without a capital. #allaboutprogramming62

Comments System

blogger/disqus/facebook