View previous topic :: View next topic |
Author |
Message |
christian.koji
Joined: 12 May 2010 Posts: 16
|
Multiple files compilation |
Posted: Tue Sep 14, 2010 5:27 am |
|
|
Hey guys I'm with a problem. I'd like to compile multiple files using one file to declare variables and make #defines. The problem is: if I have a
main.c
Code: |
#include <variable.c>
#include <defines.c>
#include <functions.c>
...
main(){
sum();
...
}
|
variable.c
defines.c
Code: |
#define max 10
#define min 0
|
functions.c
Code: |
int sum(){
c = a+b;
}
|
When I compile it generates an error, it says that the variables a, b and c are not defined. I'd like to know how do I compile these files in ccs without using extern and still use the variables as globals. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Sep 14, 2010 6:58 am |
|
|
Are you working in CCS directly, or using MPLAB?.
What you describe is totally correct, and will work. _However_ if you are working in MPLAB, it is _vital_ that only the 'main' file is in MPLAB's file inclusion list. Otherwise it tries to load an compile the 'include' files 'on their own', and will give errors such as you are describing.
It'd be 'normal practice' to use '.h' extensions for the include files, rather than .c. to make it clear that that these are not 'stand alone'. CCS is a little 'naughty' in their own examples in this regard....
Best Wishes |
|
|
christian.koji
Joined: 12 May 2010 Posts: 16
|
|
Posted: Thu Sep 16, 2010 10:23 am |
|
|
I'm using CCS directly, but it generates the error =/.
I tried to use .h extension also but get the same errors.
Is there some project configuration I have to do to deal with multiple files? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Sep 16, 2010 2:39 pm |
|
|
Show the header (the part above including variable.c).
You would again get this as an error, if there was a function definition here, without a closing brace. You also need the processor define, and fuses, before anything else.
Best Wishes |
|
|
|