CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Multiple files compilation

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
christian.koji



Joined: 12 May 2010
Posts: 16

View user's profile Send private message

Multiple files compilation
PostPosted: Tue Sep 14, 2010 5:27 am     Reply with quote

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
Code:

int a,b,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: 19537

View user's profile Send private message

PostPosted: Tue Sep 14, 2010 6:58 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 16, 2010 10:23 am     Reply with quote

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: 19537

View user's profile Send private message

PostPosted: Thu Sep 16, 2010 2:39 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group