![]() |
Multiple Definitions
I've created a new file, where I keep all of this years code. When I compile my project I get an error saying symbol 'ReleasingBall' has multiple definitions.
Here's how my files are organized: custom_routines.h Code:
#ifndef _CUSTOM_ROUTINES_H_Code:
#include <timer.h>Code:
//.. |
Re: Multiple Definitions
I'd think that variable would need to be declared global and then marked extern in all other files that use it. Or something like that, I forget the exact procedure.
|
Re: Multiple Definitions
When you copy a project to a new folder, you should Clean (or Build all) to get rid of any leftover pointers to the old files. Until you do that, the linker appears to get confused, complaining about what looks like duplicate copies of the object files.
[Edit:] Oh! You're not supposed to declare variables in .h files. The bool ReleasingBall; line belongs in custom_routines.c instead, and what goes in custom_routines.h should be extern bool ReleasingBall; (though I'm not sure where bool is defined). |
Re: Multiple Definitions
You want the compiler to encounter only one declaration for the variable as it processes the set of source source files. Your technique above is designed to prevent multiple references or forward references to be encountered , not multiple variables. I'm sure your custom_routines.h file is processed when you compile multiple separate source files.
So do his, change the statement in custom_routines.h to an external reference and declare storage for the variable in ONLY one source file. In custom_routines.h, do this: #ifndef _CUSTOM_ROUTINES_H_ #define _CUSTOM_ROUTINES_H_ ... extern bool ReleasingBall; ... #endif In custom_routines.c, do this: .... #include <timer.h> #include "custom_routines.h" bool ReleasingBall; // defined only here! // function definitions ... One last thing, it is generally considered bad style to define storage in a header file for exactly the reason you have encountered. HTH |
Re: Multiple Definitions
Quote:
I defined bool my self with a few typedefs and defines :) |
| All times are GMT -5. The time now is 18:14. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi