3

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?

Dean P
  • 1,841
  • 23
  • 23
  • 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? –  Feb 21 '16 at 17:55
  • Typo and not inconsistency in the real files. Post Corrected – Dean P Feb 21 '16 at 18:05

1 Answers1

0

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.

Careful Now
  • 260
  • 1
  • 9
  • The Arduino environment calls source files "libraries". It does not use static or dynamic library objects. –  Feb 21 '16 at 17:54
  • What you're suggesting is still wrong. The steps that the OP is describing for adding a library are generally correct for the Arduino environment, and defining functions in header files is absolutely *not* normal in C. –  Feb 21 '16 at 17:58
  • It is quite normal for code that I have seen. Anyway this will just end up i an argument so I'm out – Careful Now Feb 21 '16 at 18:01