Compiling C under linux/UNIX

Last update on August 6, 2009 11:06 AM by jak58
Published by jak58

Compiling C under linux/UNIX





Introduction


Under linux, the C compiler is gcc. It is set as default under several distributions but not on Debian. You should install aptitude install gcc

Gcc


Gcc is the acronym for GNU compiler collection created by the GNU project. This is a collection of integrated software capable of compiling various programming languages including C, C + +, Objective-C, Java, Ada and Fortran. It is used for the enhancement of all freeware. Linux OS depend directly of the GCC function.

The abbreviation GCC determines three different entities:

1. The complete collection of compilers;
2. Part common to all compilers;
3. the C compiler itself.

To refer specifically to the compilers of each language, it refers as:
  • GCC for C
  • G++ for C++
  • GCJ for Java
  • GNAT for Ada
  • Gfortran for Fortran
  • GPC for Pascal
  • GHDL for VHDL


GCC also has a tool for debugging, GNU Debugger (gdb). Although not part of GCC, however Valgrind is preferred for testing in more depth, particularly to search for memory leaks.


GNU Debugger (gdb) is the debugging tool for GNU. However despite that Valgrind is not compiled with GCC, it is the most commonly used for serious troubleshoot.

Syntax GCC


Below are the two main commands of gcc for c :


$ gcc masource.c ==> creates executable a.out to be launched with. / A.out.

$ Gcc-o-<name_of_program> c <mysource>. C ==> The argument o-enables you to choose the name of the executable that will emerge from this compilation.
Best answers for « Compiling C under linux/UNIX » in :
Where to find a C/C++ compiler Show Where to find a C/C++ compiler On Linux the gcc compiler is already available. To use it type in: gcc –o executable source(s) For Windows it’s quite different: click on the link below to find a list of free C/C++ compilers for...
Linux - Compiling the kernel Show Compiling the kernel In this article, compiling the kernel under Linux is explained. The following explanations are based on version 2.4.20 of kernel, i.e. the most recent version of the kernel at the time this article was written (March 2003)....
Compiling an assembly program with Nasm ShowCompiling an assembly program with Nasm Intro With LInux With Windows Intro Netwide Assembler (NASM) is an assembler and disassembler for the Intel x86 architecture and is commonly used to create 16-bit, 32-bit (IA-32) and 64-bit...
Compiling a program in C with Dev C++ on Vista ShowCompiling a program in C with Dev C++ on Vista Compiling a C source code under Vista with Dev C++, can be a quite difficult procedure. Quick solution: the g++ compiler To be used with Dev-PSV: Go to Tools/compiler options and...
List of open ports in command line ShowList of open ports in command line Whether you're running Windows or Linux / Unix, the following command in (console) will display the list of open ports on your computer: netstat -a For the use of advanced graphics tools, see What...
Linux - The shell ShowIntroduction to the shell The command interpreter is the interface between the user and the operating system, hence the name "shell". The shell therefore acts as an intermediary between the operating system and the user thanks to command lines...
Linux - The Vi editor ShowIntroduction to Vi Despite its very limited ergonomics, Vi i is one of the most popular text editors texte under Unix type systems (with Emacs and pico). Under Linux, there is a free version of Vi called Vim (Vi Improved). Vi (pronounced vee-eye)...
UNIX Commands ShowTable of the main UNIX commands Unix Commands Description Options ls lists the content of a directory -a Displays all files, including hidden files -I Displays a...