gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > issues with compiling stuff

#20219 - Darmstadium - Tue May 04, 2004 10:42 pm

I want to compile certain parts of my project seperately. Ok, so I compile my different source files and make .o files. When I try to link them I get errors. I'm trying to use variables/functions from one file in another file, I get undefined reference errors. I tried to declare some external variables/functions using extern but it doesn't work when I try to link my project, though it does compile. Could you please tell me how to do this? Thanks for your help

#20220 - poslundc - Tue May 04, 2004 10:45 pm

Extern-ally declared variables must exist in some other part of the program in order to be linked properly. Make sure that you are defining the globally-shared variables somewhere, ie.

Code:
foo.c:
   int      myFooGlobal;      // primary definition of myFooGlobal

bar.c:
   extern int   myFooGlobal;   // reference to external variable


Dan.

#20222 - Darmstadium - Tue May 04, 2004 10:51 pm

I checked every file and the variables/function that I try to declare with extern do exist. I even looked in the .o file that contains the variables I want to use and they are declared in there! I am perplexed

#20225 - sajiimori - Wed May 05, 2004 12:27 am

Try compiling Dan's small example, and try making one of your own. Post any errors you encounter.

If you only get errors with your larger programs, try to pare them down to the smallest portion that has the problem, then post that along with the errors.