Sign in to follow this  
DanMarshall

DevC++ Multiple files Bug?!

Recommended Posts

DanMarshall    184
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

Share this post


Link to post
Share on other sites
vinb    218
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.

Share this post


Link to post
Share on other sites
smart_idiot    1298
main.c

#include "my_header.h"

int main()
{
my_function(my_variable);
return 0;
}



my_header.h

#ifndef MY_HEADER_H
#define MY_HEADER_H

extern 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.
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
DanMarshall    184
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...!)

Share this post


Link to post
Share on other sites
Toolmaker    967
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this