Hey all. I am having an infuriating problem with my code. About a month ago I began to program a game in C with openGL, and XCode was great for getting started. However I stopped working on it for weeks until this morning, and for some reason it suddenly is not wanting to compile, giving me a 'multiple definitions' error for a constant float in on of my header files, even though I did a #ifndef-#define-#endif thing.
In a simplest case scenario, the project is a Carbon Application with three classes: main.c, util.h, and util.c, that look like the following:
main.c:
util.h:
util.c:
And that's it. It just doesn't like that constant float, when it didn't have a problem with it a month ago. The error looks something like:
If I remove util.c's include, and it's only included once, it works.
I tried fixing this by taking out the constant and code that uses it, but then it came up with a bunch of nonsensical 'undefined' errors for seemingly random things. I even tried installing an older version of XCode, and then in frustration I reinstalled the entire OS thinking that some update had effed things up, but it's doing the same thing.
So on one hand, that tells me it's the code, but on the other hand, it compiled last month just fine, and those compiler directives seem like they ought to keep that variable from being defined twice. Am I missing something! I'd really like to get back to making this game, and I'm crushed that the code isn't working now. Any help would be deeply appreciated.
In a simplest case scenario, the project is a Carbon Application with three classes: main.c, util.h, and util.c, that look like the following:
main.c:
Code:
#include "futil.h"
int main(void) {
return 0;
}
util.h:
Code:
#ifndef TEST
#define TEST
const float mat = 100.8/45.0; //it tries to define this twice, I guess
#endif
util.c:
Code:
#include "util.h"
And that's it. It just doesn't like that constant float, when it didn't have a problem with it a month ago. The error looks something like:
Code:
multiple definitions of _mat
I tried fixing this by taking out the constant and code that uses it, but then it came up with a bunch of nonsensical 'undefined' errors for seemingly random things. I even tried installing an older version of XCode, and then in frustration I reinstalled the entire OS thinking that some update had effed things up, but it's doing the same thing.
So on one hand, that tells me it's the code, but on the other hand, it compiled last month just fine, and those compiler directives seem like they ought to keep that variable from being defined twice. Am I missing something! I'd really like to get back to making this game, and I'm crushed that the code isn't working now. Any help would be deeply appreciated.