Why won't my files link?

Igor Pechtchanski pechtcha@cs.nyu.edu
Tue Feb 4 18:34:00 GMT 2003


Nick,

> I cannot fully
> compile all of the files on their own... I mean... I can do "gcc -c
> filename.c", and that works fine for all files that I am talking about.
> However, I am assuming that full compilation into ".o" files will not work
> because some of the files are not meant to stand alone.  I hope this is
> not confusing!

This actually *is* confusing.  Here is some terminology to make it easier
for you to report the exact problem you're having: "compile" means
translate from a ".c" (source) to a ".o" (object) file.  "link" means take
all the relevant ".o" (object) files (and libraries) and combine them into
an ".exe" (executable).  You "compile" by running
"$(CC) $(CFLAGS) -c [-o MODULE.o] MODULE.c", and "link" by running
"$(CC) $(CFLAGS) -o PROGRAM.exe MODULE1.o MODULE2.o $(LIBS)", where
"$(CC)" is usually "gcc", "$(CFLAGS)" is something like "-O2" or "-g", and
"$(LIBS)" is something like "-lpopt"...

Compilation into ".o" files is meant to be stand-alone.  A ".o" file can
reference variables and functions that are not included in it (but are
included in another ".o" file, hopefully).  The linking step, among other
things, resolves the "undefined" symbols in each ".o" file or library and
matches them with those present in the other ".o" files and libraries.

The above is pretty simplistic, but should be enough to get you started.
It is also helpful to run "info gcc" for the explanation of the flags.

So, now that you know the terminology, please post the exact gcc command
line you use to *link* your files, and the exact error messages you get
when you try to link (I assume compiling does not produce any errors for
you).
	Igor

On Tue, 4 Feb 2003, Nick Miller wrote:

> Hey!!!  Thank you both for your quick responses!  To clear things up, let
> me say this... all of my files are in the same directory.  This directory
> is...
>
> c:/cygwin/home/Owner/
>
> So, then when I want to run an executable that is in that directory, I
> have to use the "./" prefix to run an executable that has been created.
> Elfyn already addressed that though, so I should be able to change my path
> variable and make it so that I do not have to append the "./" prefix for
> the executables.  Executable meaning using the ".exe" suffix.  All of the
> header files and C files are in the same directory, as I said.  I will try
> the stuff that Elfyn suggested and get back to you.  I cannot fully
> compile all of the files on their own... I mean... I can do "gcc -c
> filename.c", and that works fine for all files that I am talking about.
> However, I am assuming that full compilation into ".o" files will not work
> because some of the files are not meant to stand alone.  I hope this is
> not confusing!
>
> Nick
>
>
> On Mon, 3 Feb 2003, Max Bowsher wrote:
>
> > Elfyn McBratney wrote:
> > >> So I am new to Cygwin, but I am enjoying it so far.
> > >
> > > Kewl! :::::::-)
> > >
> > >> I am having a
> > >> problem, though, please respond if you can... I have three C files
> > >> (all ending in .c), and I can compile them with GCC by using the -c
> > >> switch. Then, I want to link all three of the object files that I
> > >> have created (ending in .o) and make an executable which uses all
> > >> three.  My file called main.c has two include lines, which says to
> > >> include "io_functions.h" and "fun.h".  Then I am using this line to
> > >> link everything and make the executable...
> > >
> > > Right. To all of the files you are tryin to compile (the *.c files
> > > and the
> > > *.h files) reside in the same directory? If so you should be using a
> > > command similar to
> > >
> > > $ gcc -I.-c fun.c
> >
> > Missing space between '-I.' and '-c'. Why would you want to use -I. ?
> >
> > #include "file" searches there anyway.
> >
> > > You might try compiling each file (into an executable) before,
> > > in-case there are errors, so you'll have peace of mind that they'll
> > > actually compile.
> >
> > Do you mean (into an object) ?
> >
> > Max.

-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

Oh, boy, virtual memory! Now I'm gonna make myself a really *big* RAMdisk!
  -- /usr/games/fortune


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list