[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-ppc
Subject: RE: Compile problems
From: Steve Revilak <revilak () umbsky ! cc ! umb ! edu>
Date: 2000-07-10 11:46:42
[Download RAW message or body]
> I have been trying to compile some c code and running into problems. I
> finally reduced the problem to how external variables are being handled.
Here is test1.c
> #include <stdio.h>
> extern int a;
> main()
> {
> printf("Hello world\n");
> a=2;
> testfun();
> a=4;
> testfun();
> }
Okay, 'a' is global variable declared to be in some other file.
> And here is test2.c
> extern int a;
> testfun()
> {
> printf("Now got into testfun\n");
> printf("a = %i\n",a);
> }
Again, same thing. 'a' is given global scope and you're telling the
compiler that it's declared somewhere else.
> gcc test1.c test2.c
> and I get the following list of errors:
> /tmp/cca2PpML.o: In function `main':
> /tmp/cca2PpML.o(.text+0x26): undefined reference to `a'
Right. Because both files are referencing this variable 'a' that isn't
declared anywhere. Either get rid of the 'extern' in one of the files
or create a header file with a declaration for the variable and #include
it in test1.c and test2.c.
--
Steve Revilak
revilak@umbsky.cc.umb.edu
** Sent via the linuxppc-user mail list. See http://lists.linuxppc.org/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic