View previous topic :: View next topic |
Author |
Message |
adamp524
Joined: 06 May 2010 Posts: 22
|
Compiler Error: Function used but not defined |
Posted: Thu Oct 27, 2011 8:16 am |
|
|
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: 19568
|
|
Posted: Thu Oct 27, 2011 10:04 am |
|
|
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
|
|
Posted: Thu Oct 27, 2011 2:43 pm |
|
|
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: 19568
|
|
Posted: Thu Oct 27, 2011 3:04 pm |
|
|
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
|
|
Posted: Fri Oct 28, 2011 10:44 am |
|
|
Ah, I understand!
Importing the source files using #include seems to work fine!
Thanks |
|
|
|