libraries directory not detecting my include files

Hi All,

I'm having problems with my include files

here is a sample code to replicate the problem .

I'm running OSX . Arduino IDE 1.8.2

#include "Motor.h"


void setup() {

  Serial.begin(57600);
  
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

I keep getting

"fatal error: Motor.h: No such file or directory
#include "Motor.h"

Motor.h is located in the following directory

MyCode (directory)

-> MyCode (directory)
--> MyCode.ino

-> libraries (directory)
--> Motor (directory)
---> Motor.h
---> Motor.cpp

I've looked around the forums and this is what everyone is suggesting but It is simply not working

meat030:
MyCode (directory)

Is that the sketchbook folder set in File > Preferences > Sketchbook Location?

Hi Pert,

No it is not there.

Are there additional steps? Previously I did not have to do this.

You can't just put the library in any random folder named libraries. The Arduino IDE looks in a few specific places for libraries. The place where user installed libraries are supposed to be is {sketchbook folder}/libraries. You can set the location of the sketchbook folder to anything that is convenient in the IDE preferences. If for some reason that doesn't suit what you're trying to do then please explain further and I can help you out.

Thank Pert,

I wasn't aware that libraries are suppose to be located in {sketchbook folder}/libraries.

I thought that if I have a project directory

I could simply create a "libraries" directory within the project directory and put all my include files in there. My understanding was that since libraries was in the "current working directory of my sketch" it would be detected.

That way if I need to hand over the project code to someone else I would just have to zip up that project directory.

If that approach not correct?

Usually I think it’s better to install libraries to a common location so that all your projects can share the same library but in the case of wanting a project to be self contained it definitely makes sense to put it all in the project folder. This is possible but you have to make a couple of changes:

Change your folder structure to:

MyCode
|_MyCode.ino
|_src
|_Motor
|_Motor.h
|_Motor.cpp

Change your code from:

#include "Motor.h"

to:

#include "src/Motor/Motor.h"

Unfortunately some libraries use incorrect include syntax, which still works when the library is installed in one of the standard libraries folders but doesn’t when you try to bundle a library with a sketch. An example is if Motor.cpp has the line:

#include <Motor.h>

you need to change that to:

#include "Motor.h"

The quotes indicate that the current directory should be checked for the file first before looking in the other include folders. The angle brackets syntax will not cause the current folder to be checked. You need to remember to use the quotes include syntax in any sketch that’s including a bundled library.

You also have the option of just putting the library source files directly in the sketch folder but that clutters up both the folder and the IDE because those files will appear as tabs when the sketch is opened. If the user is unlikely to have the need to edit those files it’s much better to put them in their own folder.

I just tried moving my libraries to

sketchbook folder/libraries

and the code compiles.

The thing is that if I have multiple libraries and multiple projects

How will I export my projects easily if I have to hunt through the libraries folder to look for which libraries I've used in my sketch.

Read my last reply. I just explained it to you.

I will look into your project structure that you listed above and will see how that goes.

Sorry posted that just before seeing your reply pop up.

Thanks so much !!!
Will update on how I go

Cheers