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

Compiler Error: Function used but not defined

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



Joined: 06 May 2010
Posts: 22

View user's profile Send private message

Compiler Error: Function used but not defined
PostPosted: Thu Oct 27, 2011 8:16 am     Reply with quote

Hi,
I'm writing code using the CCS compiler and want to use multiple files for the project but I'm getting the error:
Error 112 ...... Function used but not defined: ...read_heading SCR=531

Here is the code I have below:

main.c
Code:
#include <main.h>
#include "compass.h"

void main()
{
read_heading();
}


compass.c
Code:
#include "compass.h"

int read_heading(void)
{
//Function code
}


compass.h
Code:
//Defines used in compass.c
#define def1 0
#define def2 1

/* Function prototypes */
int read_heading(void);


Does anyone know what I'm doing wrong? It seems that the compiler is not finding the function read_heading() in compass.c
By default when compiling are all .c files included in the build?

Thanks,

Adam
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Thu Oct 27, 2011 10:04 am     Reply with quote

Nothing is ever included without you telling the compiler to do so.
If you look at things like the usb examples, the main code includes usb.c, and this then includes usb.h.
So the prototype is being loaded, but not the code. Hence the error.

Best Wishes
adamp524



Joined: 06 May 2010
Posts: 22

View user's profile Send private message

PostPosted: Thu Oct 27, 2011 2:43 pm     Reply with quote

Ok thanks.
Although I thought it was bad practice to include .c files. Should all includes not just be header files?

Thanks,

Adam
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Thu Oct 27, 2011 3:04 pm     Reply with quote

This is down to CCS not really using the old standards.
Basically in original C programming, _everything_ you included, would be called a .h file, not a .c file. Only your actual compilable files would be called .c files. .c files for parts of the code, would then need to be _separately_ compiled, and the resulting object files, linked in the final build phase of the project.
In your case, you have code that needs to be compiled, so if you wanted to use the old standard, you would _either_ precompile this, and then specifically import this into the code (CCS does not really have a traditional linker), or you just have to include the .c file (or rename it as a .h file....). Perhaps use a standard like:

compass_hdr.h //for the headers
compass_code.h //for the actual compilable code parts

to distinguish the parts that are compilable code, as opposed to simple headers.

CCS generally though does not make any distinction between .c, and .h files, and in their examples, you will find the names used without really any pattern at all.....

Best Wishes
adamp524



Joined: 06 May 2010
Posts: 22

View user's profile Send private message

PostPosted: Fri Oct 28, 2011 10:44 am     Reply with quote

Ah, I understand!

Importing the source files using #include seems to work fine!

Thanks
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