Getting Windows OS ready for C Coding

<<Previous

Next >>





Choose the variant of C compiler

There are too many C compilers in the market. Most commonly used are:

  • GNU GCC - Popular C++ compiler
  • Portable C
  • Intel C++ compiler
  • Microsoft VC++ - only for windows
  • Borland C++
  • Turbo C++ - not released after 1996

Most commonly used is GNU GCC. To use GCC, you would require either Cygwin or MinGW.

  • Cygwin
    • creates an Unix environment for Windows.
    • C programs written on Cygwin can run on Unix as well.
    • C programs written on Unix can also be run on Cygwin on Windows.
  • MinGW
    • C programs written on MinGW can run on windows.
    • If you write code that does not use Windows libraries, it can still work on Unix.
    • If you use Windows libraries, it will work on windows but not on Unix

Download Essentials


For this tutorial, We are going to install Cygwin. Cygwin setup-x86_64.exe can be downloaded from https://www.cygwin.com/





For other variants, please refer to https://gcc.gnu.org/install/binaries.html





For this tutorial, we are going to set the environment as shown below




Cygwin Packages installation

Run setup-x86_64.exe . Please follow the steps in the installation wizard







Please follow the steps to choose the packages wget, make, gcc-g++, debug, devel, libs, and utils for installation.





You can either click on setup-x86_64.exe using the UI to choose the utilities mentioned above or use the command line:

setup-x86_64.exe -q -P wget,gcc-g++,make,diffutils,libmpfr-devel,libgmp-devel,libmpc-devel

Download and Install the C variant you chose

Download the GCC source code from one of the mirror sites listed in:
       https://gcc.gnu.org/mirrors.html

Copy the file to a specific folder and Extract the gcc using the following command

tar xzf gcc-9.3.0.tar.gz

Once the file is extracted, a new folder named gcc-9.3.0 will be created. Execute the following commands one by one

cd gcc-9.3.0

./contrib/download_prerequisites

Once the download prerequisites is complete, Execute the following commands one by one to choose the languages to be supported by gcc. As shown below, 'configure' is used to set the configurations before doing the build

cd ..
mkdir objdir
cd objdir
$PWD/../gcc-9.3.0/configure --prefix=$HOME/GCC-9.3.0 --enable-languages=c,c++

Build the source using the 'make' command. You can use make -j followed by to speed up the build process using multiple threads

 make -j4

make -j4 might take hours depending on the speed of the machine

Once the make has completed successfully, execute the 'make install' command to copy the compiled code to various locations

make install

Set the Path

Set the path of the cygwin installation in PATH variable. If you have installed cygwin in the location "C:\cygwin64", then you can set PATH using the command prompt:

SET PATH=%PATH%;"C:\cygwin64\bin"

Install the IDE or Editor if you want

You can install any of the popular IDEs, some of those being: Eclipse for C/C++, Code::Blocks, NetBeans, Geany, Visual Studio, Code. It is not mandatory to have an IDE. You can also use simple editors available for your OS. On Windows: You can use Notepad. Or You can download and use editors like Textpad.

If you are managing a large project in C, IDE would be of good help.

For this tutorial, we will be using Code::blocks. You can download Code::Blocks from:

 		http://www.codeblocks.org/downloads/binaries 


Get the IDE ready


Once the IDE is installed, Open it and Go to Settings menu and click on Compiler



In the Compiler window, Choose GCC compiler. Click on 'Toolchaining' tab and type cygwin Installation bin location. For this tutorial, it is "C:\Cygwin\bin" and click on Ok.




Understand the Basics on how to use the IDE

In Code:Blocks, on the left "Management" tab, click on Files tab and choose a Drive. Say "E:". Click on the drive name, right click and choose 'New file'.




In the dialog box that appears, type File name say 'Program1.c' and click ok. You can see the file created on the left side.



Click on the new file created and type your C program on the right editor. You can write the code with an error, so as to see how to handle errors



Click on 'compile' as shown below from the build menu



Compilation errors are display at the bottom.



Click on the error displayed and correct the issues in the editor and Save. Click on 'compile the file' from build menu.



Once code is compiled without any errors, you can find two additional files created with the same file name but with extensions '.o' for object file and '.exe' for executable file. In this case, it would be 'Program1.o' and 'Program1.exe'


<< Previous

Next >>







Getting Windows OS ready for C Coding

<<Previous

Next >>





Choose the variant of C compiler

There are too many C compilers in the market. Most commonly used are:

  • GNU GCC - Popular C++ compiler
  • Portable C
  • Intel C++ compiler
  • Microsoft VC++ - only for windows
  • Borland C++
  • Turbo C++ - not released after 1996

Most commonly used is GNU GCC. To use GCC, you would require either Cygwin or MinGW.

  • Cygwin
    • creates an Unix environment for Windows.
    • C programs written on Cygwin can run on Unix as well.
    • C programs written on Unix can also be run on Cygwin on Windows.
  • MinGW
    • C programs written on MinGW can run on windows.
    • If you write code that does not use Windows libraries, it can still work on Unix.
    • If you use Windows libraries, it will work on windows but not on Unix

Download Essentials


For this tutorial, We are going to install Cygwin. Cygwin setup-x86_64.exe can be downloaded from https://www.cygwin.com/





For other variants, please refer to https://gcc.gnu.org/install/binaries.html





For this tutorial, we are going to set the environment as shown below




Cygwin Packages installation

Run setup-x86_64.exe . Please follow the steps in the installation wizard







Please follow the steps to choose the packages wget, make, gcc-g++, debug, devel, libs, and utils for installation.





You can either click on setup-x86_64.exe using the UI to choose the utilities mentioned above or use the command line:

setup-x86_64.exe -q -P wget,gcc-g++,make,diffutils,libmpfr-devel,libgmp-devel,libmpc-devel

Download and Install the C variant you chose

Download the GCC source code from one of the mirror sites listed in:
       https://gcc.gnu.org/mirrors.html

Copy the file to a specific folder and Extract the gcc using the following command

tar xzf gcc-9.3.0.tar.gz

Once the file is extracted, a new folder named gcc-9.3.0 will be created. Execute the following commands one by one

cd gcc-9.3.0

./contrib/download_prerequisites

Once the download prerequisites is complete, Execute the following commands one by one to choose the languages to be supported by gcc. As shown below, 'configure' is used to set the configurations before doing the build

cd ..
mkdir objdir
cd objdir
$PWD/../gcc-9.3.0/configure --prefix=$HOME/GCC-9.3.0 --enable-languages=c,c++

Build the source using the 'make' command. You can use make -j followed by to speed up the build process using multiple threads

 make -j4

make -j4 might take hours depending on the speed of the machine

Once the make has completed successfully, execute the 'make install' command to copy the compiled code to various locations

make install

Set the Path

Set the path of the cygwin installation in PATH variable. If you have installed cygwin in the location "C:\cygwin64", then you can set PATH using the command prompt:

SET PATH=%PATH%;"C:\cygwin64\bin"

Install the IDE or Editor if you want

You can install any of the popular IDEs, some of those being: Eclipse for C/C++, Code::Blocks, NetBeans, Geany, Visual Studio, Code. It is not mandatory to have an IDE. You can also use simple editors available for your OS. On Windows: You can use Notepad. Or You can download and use editors like Textpad.

If you are managing a large project in C, IDE would be of good help.

For this tutorial, we will be using Code::blocks. You can download Code::Blocks from:

 		http://www.codeblocks.org/downloads/binaries 


Get the IDE ready


Once the IDE is installed, Open it and Go to Settings menu and click on Compiler



In the Compiler window, Choose GCC compiler. Click on 'Toolchaining' tab and type cygwin Installation bin location. For this tutorial, it is "C:\Cygwin\bin" and click on Ok.




Understand the Basics on how to use the IDE

In Code:Blocks, on the left "Management" tab, click on Files tab and choose a Drive. Say "E:". Click on the drive name, right click and choose 'New file'.




In the dialog box that appears, type File name say 'Program1.c' and click ok. You can see the file created on the left side.



Click on the new file created and type your C program on the right editor. You can write the code with an error, so as to see how to handle errors



Click on 'compile' as shown below from the build menu



Compilation errors are display at the bottom.



Click on the error displayed and correct the issues in the editor and Save. Click on 'compile the file' from build menu.



Once code is compiled without any errors, you can find two additional files created with the same file name but with extensions '.o' for object file and '.exe' for executable file. In this case, it would be 'Program1.o' and 'Program1.exe'


<< Previous

Next >>







Learn about Hashing and Hash table

Learn Expression Tree

OS Kernel Architecture

OS Arcitecture of Windows, Linux and MacOS

Learn OS scheduling Algorithms