DevC++ Multiple files Bug?!
Is there a problem using multiple source files in DevC++? I'm trying to put all my collision If statement into a specific function in a separate .c file, but it won't compile/ link properly... It picks out variables saying it doesn'trecognise them. I've tried including the file in the main header file, the main.c file... am I doing something wrong or what?
I'm using the version that comes with All in One 2ed, so it may be quite old...
Any help greatly appreciated.
dan
I've never used DevC++, but I know that it was very confusing with MSVC++ once I started using multiple files. The problem I had was with redefinitions of classes and constants. The way around that was with preprocessor directives like #ifndef/#endif.
I don't know if that applies to what you're doing, but hope it helps.
I don't know if that applies to what you're doing, but hope it helps.
main.c
my_header.h
another_file.c
#include "my_header.h"int main() { my_function(my_variable); return 0; }
my_header.h
#ifndef MY_HEADER_H#define MY_HEADER_Hextern int my_variable;void my_function(int);#endif
another_file.c
#include "my_header.h"int my_variable = 5;void my_function(int number) { // TODO: Do something. }
If you want variables to be cross-file in a project, you have to make them extern, like the previous poster said. That should be in a header file included in any file needing that variable. You also have to redeclare that variable somewhere else, but not as an extern. That's the only other time you'll need to declare it. You also do that with classes if you want them globally across files.
Aaaah, I see.
My fault, then...! Apologies to DevC++'s creators for jumping to the conculusion that their program is evil... it's just I nearly punched my monitor this morning (game's not going so well...!)
My fault, then...! Apologies to DevC++'s creators for jumping to the conculusion that their program is evil... it's just I nearly punched my monitor this morning (game's not going so well...!)
Actually, the makers of Dev-C++ don't have anything to do with the compiler. The compiler that's used in Dev-C++ is MinGW, which is the GCC port for Windows.
Dev-C++ just happens to have the compiler with it.
Toolmaker
Dev-C++ just happens to have the compiler with it.
Toolmaker
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement