| |||||||||||
| |||||||||||
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.cIn 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.cbut 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 07:04:58) Associated topics are indexed under C201 - C and C based languages - C Language FundamentalsA168 - Web Application Deployment - Compiler and Development Tools
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 1759 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 at 50 posts per pageThis 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). |
| ||||||||||
PH: 0800 043 8225 or 01225 708225 • FAX: 0845 8382 405 or 01225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||