3
votes

Context: I would like to add a custom library to a piece of Arduino code in the Arduino 1.5.7 IDE to ensure code is decentralized and readable

Attempted solution:

I make a folder called "mathsfunctions". In it I put two text files, one with a .c and another with a .h name extension.

The .c file is called "mathsfunctions.c" and has the following code in it:

#include "mathsfunctions.h"
int multiply (int a, int b)
{
 return a*b;
}

The .h file is called "mathsfunctions.h" and has the following code in it:

int multiply (int, int);

In the main file, I add in the following include preprocessor directive:

#include "mathsfunctions.h"
//The rest of the code

After the above was coded, I imported the library. To do this, I did the following:

Toolbar -> Sketch -> Add Library -> c:.....\mathsfunctions

I can confirm that this is indeed imported because after doing such action, the same mathsfunctions folder appears in the Arduino libraries folder:

C:.....\Arduino\libraries\mathsfunctions

Problem: Upon compiling, the error dialogue box gives the following error:

mathsfunctions.h: No such file or directory

Assistance Required: Any idea on what the problem could be?

1
You've used about three different names for your files in your question (mathsfunction.h, mathsfunctions.h, matshfunctions.h). Is this just a typo, or is there an inconsistency in your real file names too?user149341
Typo and not inconsistency in the real files. Post CorrectedDean P

1 Answers

0
votes

You should only have put the header and the source in the same directory as your main file. Also I would suggest putting the implementation in the header since this is the way that people generally include extra functions in C. I am unsure if C supports extra source files but it does support extra headers.