Go Down

Topic: Importing .ipp files - works in standard library folder, doesn't work locally (Read 2220 times) previous topic - next topic

mcmenon

I have a library with 2 files:

MyFile.h
MySecondFile.ipp

MyFile.h has only the following content:
#include "MySecondFile.ipp" [edited to add quotes]

It is basically a dummy file to see if I can #include things

When I put these into a folder called MyFiles and place them into Arduino's library folder, I can compile my .ino file that says:

#include <MyFile.h>

With no problems (note that this means that it is including MyFile.h AND MySecondFile.ipp).

Here's the problem: if I take these files (MyFile.h and MySecondFile.ipp) and put them into the SAME folder as my sketch, and I edit my sketch to say:

#include "MyFile.h"

I get the error:

fatal error: MySecondFile.ipp: No such file or directory

This means that it is able to include MyFile.h, but not able to include MySecondFile.cpp, even though this does work when I have these files properly located in the default library location. It seems like the #include function has some rules that I'm not aware of and the documentation is a bit sparse. I've played around with this a bit and it seems this problem only happens with the *.ipp extension. When I make up an extension (*.foo, for example) it is unable to import the file regardless of where it is. And if I use a different extension (*.hpp, for example) it will import multiple of these files from either folder location.

Any help on why this is happening and how to work around it (I want my library that has .ipp files to be saved locally) is greatly appreciated.

Coding Badly


mcmenon

Oops, sorry, I actually did have the quotes but forgot to add them to my post. Edited to fix.

Coding Badly


So, you typed the "source code" from memory rather than using copy-then-paste.  Which means you wasted my time.

To ensure you do not waste any more of my time you will have to provide an exact copy of all the files necessary to reproduce what you are seeing.  I suggest using 7-Zip to archive the files then attach the archive to a post.

However, you may get lucky: someone more generous than me may try to help with what you have provided.


mcmenon

I apologize - I originally copy / pasted from my code but made a mistake and fixed it (poorly) by hand. Should not have done that and I appreciate how annoying it can be to deal with when people do this kind of thing.

I am attaching the files now - the 'library' files are together in a zip, and the sketch file is in a separate file. Please note that my sketch currently has the <> around the included file. When I moved the 'libraries' into the same folder as my sketch I replaced the <> with ""

Please let me know if there is anything else I can do to clarify this. Apologies again, I definitely appreciate any help I can get on this.

UKHeliBob

Quote
When I put these into a folder called MyFiles and place them into Arduino's library folder, I can compile my .ino file that says:

#include <MyFile.h>
As a matter of interest, which Arduino libraries folder is your MyFiles folder in ?  The system libraries folder or the one in your sketchbook folder ?
Is the folder really named MyFiles or has an extra s sneaked into the name when you posted the question ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

mcmenon

> As a matter of interest, which Arduino libraries folder is your MyFiles folder in ?

For the library files / locations there are two cases

case 1) MyFile.h and MySecondFile.ipp are located in a folder called MyFiles. This folder is located in the libraries folder. Specifically: Arduino/libraries. I zipped that file up and attached it above. This is the case where I am able to #include both files without errors.

case 2) MyFile.h and MySecondFile.ipp are located in the same folder as my sketch - they are not in another folder called MyFiles in that case. In this case I am unable to import the .ipp file, but I can import the .h file. Note also that in this case I made a modification to the sketch (changed from #include <MyFile.h> to #include "MyFile.h")

> The system libraries folder or the one in your sketchbook folder ?

Short answer (as described above): I have tried both. Another thing I have tried based on a suggestion I read elsewhere: creating a 'libraries' folder within the folder that my sketch is located, and saving the .h and .ipp files there. And modifying my #include statement to point to that folder. In that case I saw the same failure to import the .ipp file

> Is the folder really named MyFiles or has an extra s sneaked into the name when you posted the question ?

Yes the FOLDER is named MyFiles, but the files do not have the 's' on the end. Now that I think about it that's pretty bad naming convention on my part, but it was able to include the files just fine (in the case when they were in the Arduino/libraries folder). I guess it just searches for .h files through all the folders in the Arduino/libraries folder?

I'm running this on a OSX 10.11.4. Not sure if that matters! Please let me know if I didn't answer your questions.

Coding Badly


Ah, now I get it.  The Arduino IDE copies the contents of the sketch to a directory in %TEMP% then builds from there.  dot-ipp files are not copied.  You will have to use a different extension, a different build tool, or make a small change to the IDE.


mcmenon

> a different build tool

This is interesting to me. I'm thinking of using this:

https://github.com/arduino/Arduino/blob/ide-1.5.x/build/shared/manpage.adoc

And it looks like from this I can set preferences, even temporarily. I imagine there's a way to set preferences to copy this file over. However the documentation online is pretty sparse. I looked through all the options on the current preferences.txt but didn't see anything that looked right. I do know there are other preferences options that are not listed by default - is there some resource you could point me towards that might help me figure this out?

Coding Badly


Were I in your shoes I would just use a supported extension.  Using dot-ipp cannot be that important.


mcmenon

Late update:

I attempted to use a supported extension, but this is a 3rd party library and I can't just change .ipp to .hpp without everything breaking. I don't understand the difference between these and what subtleties I need to be aware of in order to import properly

Eventually I wrote a shell script that did all the following:
- copied the library in question from the LOCAL path to the DEFAULT library path
- compiled using CLI to some known folder
- wrote to the arduino from the .hex file generated in this known folder
- cleaned out the folder

This still allows me to save my library locally as I wanted. It's not perfect - for example it assumes the user hasn't changed the default location of the arduino library - but it works for now.

Coding Badly


Thank you for the follow-up.

Here's the problem: if I take these files (MyFile.h and MySecondFile.ipp) and put them into the SAME folder as my sketch...
Why?  Why do you want the library to be in the same folder as your sketch?

but this is a 3rd party library
Why does that preclude you from renaming the files?  Or getting the library author to use something more typical like "cpp" or "hpp" or just "h"?


mcmenon

> Why?  Why do you want the library to be in the same folder as your sketch?

I'd like to be able to share this project with other people. My hope was if everything is in one folder, I can make this a single git repo and others can clone it and run it without having to worry about manually installing libraries. If there's a better way to do this I would love an alternative!

> Why does that preclude you from renaming the files?

I did try renaming the files and got a pile of cryptic errors. I'm a bit out of depth at this level of programming and I wasn't sure what is the difference between an ipp and an hpp and why I can't treat them the same. I started doing some research on this but got the sense I was about to go down a very long rabbit hole, so I pulled back and did this method instead.

>  Or getting the library author to use something more typical like "cpp" or "hpp" or just "h"?

I don't know the library author unfortunately :)

Coding Badly

If there's a better way to do this I would love an alternative!
If your user is able to put a sketch in the correct location your user is also able to put a library in the correct location. 

The better way would be a brief description of how to install the library.  Or, a link to another person's description of how to install libraries.  There is a high probability that, at some point, even I wrote a description of how to install libraries.  If you can find it, you can just steal it...
https://www.google.com/search?q=site%3Aforum.arduino.cc+%22coding+badly%22+install+library

In addition, it is my understand that the Arduino IDE makes installing correctly packaged libraries quite easy.  And, if you make your sketch an example for the library, the two will be installed together with a great deal of assistance from the IDE.

Quote
I did try renaming the files and got a pile of cryptic errors.
I suspect you may find help with such things here.

Quote
I don't know the library author unfortunately :)
Did the library magically appear on your computer?  How is it possible for you to have a library with no idea from where it came?


mcmenon

> If your user is able to put a sketch in the correct location your user is also able to put a library in the correct location.

My understanding is that the location of the sketch doesn't matter - as long as it's packaged in a folder with the same name. I'm just trying to save the user a step or two re: library installation. Some of the people with access to this code may be lab techs or people that aren't very computer savvy - my hope was that I could create a single shell file that would do all the work for them.

> The better way would be a brief description of how to install the library.  Or, a link to another person's description of how to install libraries.  There is a high probability that, at some point, even I wrote a description of how to install libraries.  If you can find it, you can just steal it...
https://www.google.com/search?q=site%3Aforum.arduino.cc+%22coding+badly%22+install+library

> In addition, it is my understand that the Arduino IDE makes installing correctly packaged libraries quite easy.  And, if you make your sketch an example for the library, the two will be installed together with a great deal of assistance from the IDE.

Sorry I was unclear - I have no problem installing the libraries myself - I'm trying to make this effortless for the person that may not have such experience.

> I suspect you may find help with such things here.

Yeah, I think given enough time I could get to the bottom of it - my currently solution isn't ideal but as you might know, work priorities sometimes force a hacked (hopefully temporarily) solution in the interest of time :)

> Did the library magically appear on your computer?  How is it possible for you to have a library with no idea from where it came?

Sorry, I should say I don't PERSONALLY know the creator of the library, just his handle on Github. It hadn't occurred to me to ask him to modify his files but that's a good idea - I'll send him a note!

Go Up