#148779 - Jeremysr - Thu Jan 10, 2008 6:18 am
In the past with my DS homebrew projects that use multiple files and header files, I always had a main.h file that all my .c files included, and the main.h file had a whole bunch of defines and includes. I now realize that it's probably better to seperate all my .cpp files so they work without depending on a giant main.h file.
My problem is that I can't figure out how to make all my files "share" global variables. With my previous DS homebrew projects I just put something like "int x;" in a header file and all my files could access that variable (I actually had one .h file for each .c file, but it would just include main.h, have some function prototypes, and define global variables.) When I try to put "int x;" in a header file now, though, it gives me an error, saying:
asdf.o:/home/.../source/asdf.cpp:20: multiple definition of `x'
main.o:/home/.../source/main.cpp:5: first defined here
main.cpp includes asdf.h and asdf.cpp includes asdf.h also. And I do have the "#ifndef _asdf_h #define _asdf_h ... #endif" code surrounding my header files.
Anyone know what I'm doing wrong? (Or should I post code?)
My problem is that I can't figure out how to make all my files "share" global variables. With my previous DS homebrew projects I just put something like "int x;" in a header file and all my files could access that variable (I actually had one .h file for each .c file, but it would just include main.h, have some function prototypes, and define global variables.) When I try to put "int x;" in a header file now, though, it gives me an error, saying:
asdf.o:/home/.../source/asdf.cpp:20: multiple definition of `x'
main.o:/home/.../source/main.cpp:5: first defined here
main.cpp includes asdf.h and asdf.cpp includes asdf.h also. And I do have the "#ifndef _asdf_h #define _asdf_h ... #endif" code surrounding my header files.
Anyone know what I'm doing wrong? (Or should I post code?)