Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Compiling C programs with gcc - an overview

Gcc - the "Gnu Compiler Collection" - is used to compile AND to link C language programs in an open source environment. A single command - gcc runs a series of phases that take you from source code through to an executable program file, with the actual steps taken works out based on:
• the extensions you give for the files
• command line options

Here are the phases:
1. The C preprocessor (cpp)
2. The C Compiler
3. The Link Loader (ld)

The C Preprocessor takes directives in the source file (that's lines that start with a # character) and acts on them as appropriate - "including" standard files of definitions, replacing "defined" constants via macros, and so on.

The C Compiler takes the preprocessor output and converts it from an ASCII English-like source code into binary code suitable for running on the particular target machine. But is is NOT a complete program yet - just a section of code / a component that needs to be joined to other components.

The last phase - the Link Loader takes all of your components, adds to them others from standard libraries, and creates a complete executable program.

Notes:

a) You'll usually run a whole series of preprocessors and compiles before running a single load, as most programs comprise many source files. Example:
gcc -c tom.c
gcc -c dick.c
gcc -c harry.c
gcc -o tom tom.o dick.o harry.o

In this example, each of three source files is compiled into an object file, and those object files are them joined into an executable file. The -c options is "compile only", and the -o option requests an output file of a none-default name.

b) If you fail to give a -o options on the gcc run that generates a program file, you'll produce a program file called a.out

c) You can do a compile and load all at once:
gcc -o tom tom.c dick.c harry.c
but as your program gets larger, that gets to be more and more repeated compile work when you'll only be changing one or two out of (perhaps) hundreds of source files at a time

d) You can use the make utility to store all your gcc - and other - commands used to build a program, and by noting down in that file a series of dependencies you can
• ensure that only the phases that need re-doing are done
• store the sometimes-complex gcc instructions so you don't have to keep retyping them.
(written 2008-06-10)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C201 - C and C based languages - C Language Fundamentals
  [888] Turning C from source to a running program - (2006-10-06)
  [2005] Variables and pointers and references - C and C++ - (2009-01-23)
  [2576] What does const mean? C and C++ - (2010-01-15)
  [2842] Staring a C course with Hello World - why? - (2010-06-30)
  [3120] Learning to write good programs in C and C++ - separating out repeated code - (2011-01-04)
  [3234] Your program - you just provide the filling in the sandwich - (2011-04-08)
  [3278] Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (2011-05-05)
  [3591] Integer types, and integer overflows, in C - (2012-01-25)
  [3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
  [4324] Learning to program - variables and constants - (2014-11-22)
  [4555] Preprocessor directives in C and C++ - what they mean - (2015-10-27)
  [4566] C - why is slow to write and debug) but fast to run? - (2015-11-01)

A168 - Web Application Deployment - Compiler and development tools
  [694] Ant and Make - (2006-04-22)
  [2674] Make and makefiles - a commented example to help you learn - (2010-03-12)
  [3053] Make - automating the commands for building and installing - (2010-11-16)
  [3632] What is Make? - (2012-03-02)
  [3651] Makefile - some basics, and a demonstration - (2012-03-13)
  [3652] A Complete makefile example - (2012-03-14)
  [3658] Using Make for a distribution - (2012-03-17)
  [3666] Makefile variables - defined internally, from the command line and from the environment - (2012-03-22)
  [4013] Web Frameworks - nested templates - (2013-02-22)
  [4585] What is make? What is gcc? - (2015-11-28)


Back to
Dynamic Memory Allocation in C
Previous and next
or
Horse's mouth home
Forward to
The Composting Cone Challenge
Some other Articles
Comparing Objects in C++
What a lot of files! (C++ / Polymorphism demo)
Spam Filters ... are working!
The Composting Cone Challenge
Compiling C programs with gcc - an overview
Dynamic Memory Allocation in C
What are Unions (C programming)
Talk on TransWilts train service to Green Party
Checking server performance for PHP generated pages
Slow boot and terminal start on Linux boxes
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/1671_.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb