Mail Archives: djgpp/1997/06/06/09:52:56

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Make Info files confusing..
Date: Thu, 05 Jun 1997 23:10:04 +0000
Organization: Two pounds of chaos and a pinch of salt
Lines: 64
Message-ID: <>
References: <5n69kf$2fe$3 AT thor DOT atcon DOT com>
Reply-To: fighteer AT cs DOT com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

SteelGolem wrote:
> I can't understand how to make one (1) exe file out of many (multiple) c
> or cc files.. why does it have to be so complicated?? if ya can't show
> me that, at least show me how to make a library file (___.a),
> PLEASE!!?!?! (although both would be nice.. =P)
> thanks for ANY help!!!  --email please!

Assume you have multiple source files:  main.c, foo1.c, foo2.c, and

1) If any one of those files needs functions or variables defined in
another file (very likely), you will need to write a header file
declaring those things, and include it in each source file.  Use ""
instead of <> in the #include statement for headers you write yourself.

2) One and only one source file should contain the 'main()' function.

3) You must compile them all at once with the same command, or compile
them individually to .o files and then link them together.  Examples:

  gcc -o prog.exe main.c foo1.c foo2.c foo3.c

  gcc -c main.c
  gcc -c foo1.c
  gcc -c foo2.c
  gcc -c foo3.c
  gcc -o prog.exe main.o foo1.o foo2.o foo3.o

4) Because many subtle problems can be introduced by using multiple
source files, you SHOULD add at least the '-Wall' and '-O' options to
the compile command line.  '-g' is also valuable for debugging.  If
using separate commands, you only need to specify the options for
compilation, not for linking.

5) Errors such as "undefined reference to foo", where foo is a symbol
used in your program, indicate that you used foo but never defined it.

6) Errors such as "implicit declaration of foo", assuming you used the
'-Wall' option, indicate that you failed to declare a prototype for a
function in the appropriate header file.

For further information, consult an advanced C textbook (most beginner
textbooks stop short of working with multiple files), and - I cannot
stress this enough - look at examples of multi-module programs that
other people have written.  I taught myself C using the code for a MUD
server, and one of the things it showed me is what goes in a header file
and what does not.  Learning by example is the best way to go.

If you need more help, please email me privately as this
newsgroup/mailing list is not suited for discussing general programming


| John M. Aldrich, aka Fighteer I      |   mailto:fighteer AT cs DOT com   |
| God's final message to His Creation: | |
| "We apologize for the inconvenience."| <<< This tagline under >>> |
|                      - Douglas Adams | <<<    construction    >>> |

- Raw text -

  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019