DevC++ Multiple files Bug?!

Started by
4 comments, last by Toolmaker 19 years, 6 months ago
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
Dan Marshallwww.gibbage.co.ukhttp://gibbage.blogspot.com
Advertisement
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.
main.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. }
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
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...!)
Dan Marshallwww.gibbage.co.ukhttp://gibbage.blogspot.com
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

This topic is closed to new replies.

Advertisement