Reputation: 4114
I have a file structure as follows:
interface.h --> interface.c
|
|
effects.h --> effects.c
|
|
main
However, functions declared in effects.h are not accessible in main.
Code snippets :
main :
#include "interface.h"
#include "effects.h"
void setup() //Initialize all variables here
{
....
turnoff();
};
effects.h :
#ifndef EFFECTS
#define EFFECTS
void turnoff();
#endif
effects.c :
#include "interface.h"
#include "effects.h"
void turnoff()
{
....
};
interface.h :
#ifndef INTERFACE
#define INTERFACE
....
#endif
Error message : In function ``loop':undefined reference to ``turnoff()'
The error message doesnt make sense as loop function is empty !
Upvotes: 0
Views: 540
Reputation: 6882
I think the IDE wants *.cpp files instead of *.c files.
Anyway you should change the settings under file->preferences to get verbose compiler output. Usually this gives some hints. At least it shows you the temporary directory that contains the files that are actually compiled. This in turn allows much more precise analysis of the issue.
Upvotes: 1
Reputation: 1154
what are the flags you are using? maybe you need to declare your functions as extern explicitly?
extern void turnoff();
Upvotes: 0
Reputation: 5980
From the latest response, I feel that effects.c
is not part of the compilation. I am not aware of the development environment, but from the available data, this is my observation.
Upvotes: 0
Reputation: 62058
You need to compile and link all 3 .c files together. With gcc
it's as simple as
gcc main.c interface.c effects.c -o executable_name
Upvotes: 1