I am making progress on my own NFC532 library ( https://github.com/reducedhackers/pn532nfcshield )
What I am interested in here is how does the compiler treat the paths for files in the library . For example I can succesfully include the header from the library…
#include "pn532_i2c/pn532_i2c.h"
However inside this header file are includes for other headers in the library and I wondered what the correct format for those paths is; currently I get the usual file or directory not found error; I am using the WebIDE
pn532_i2c/pn532_i2c.h:5:38: fatal error: pn532_i2c/PN532Interface.h: No such file or directory
#include "pn532_i2c/PN532Interface.h"
That PN532Interface.h file is in the PN532 folder under the firmware folder; its path relative to the pn532_i2c.h file is ./PN532/PN532Interface.h however I have tried variations such as ;
#include "PN532Interface.h"
#include "pn532_i2c/PN532Interface.h"
#include "pn532_i2c/PN532/PN532Interface.h"
Searching down the documentation on this has not proven useful but thats not to say it does not exist; just I have not found it easy to locate an answer for so I thought is I posed it here it might help direct myself and others.
I'm working from this library which I am inhertiing from a working arduino library https://github.com/reducedhackers/pn532nfcshield
As ever thanks to anyone taking their time to read this.
^
You’d need to put the include statement the way the file containing it sees the included header file.
For imported libraries in Web IDE you’ll get a subdirectory with the library name with all its library files in it.
So in your project .ino
and additional .h
/.cpp
tabs you’d need to write
#include "libName/libName.h"
#include "libName/libExtraFile.h"
but for files that are part of the library they all live on the same level, so there you’d write
// this is libName.h
#include "libExtraFile.h"
And for your samples the same rules apply as for any project .ino
I don’t think you’ll find that in the docs as thisis default C/C++ behaviour.
I’m not sure how your lib will be named in Web IDE - either by the name you indicated in the spark.json
or by the repo name - since I usually name the repo and the spark.json
the same - saves me thinking ;-).
But if I assume it’s the spark.json
name, your includes in readtag.ino
it should look like this
#include "pn532_i2c/pn532_i2c.h"
#include "pn532_i2c/PN532/PN532.h"
#include "pn532_i2c/NDEF/NfcAdapter.h"
but
in pn532_i2c.cpp
you should write
#include "pn532_i2c.h"
since the pn532_i2c.h
lives on the same level as pn532_i2c.cpp
.
And exemplary for all files deeper down in your lib, looking at PN532.h
// not like this
// #include "pn532_i2c\PN532\PN532Interface.h"
// but
#include "PN532Interface.h"
for the same reason - same level means no path allowed.
BTW: Don’t use #include <....>
for anything other than system headers. If you are not sure if it’s a system header or not, use #include "....."
.
Thanks @scruffr I had tried that as well
In file included from readtag.cpp:1:0:
This looks like an error in pn532_i2c library. Would you like to create an issue on GitHub to let the author know?
CREATE ISSUE
pn532_i2c/pn532_i2c.h:5:28: fatal error: PN532Interface.h: No such file or directory
#include "PN532Interface.h"
^
compilation terminated.
make[1]: *** [../build/target/user/platform-6readtag.o] Error 1
make: *** [user] Error 2
I think what I may do is rebuild the whole repo with the same repo name as the spark json as well; im familiar with C treating libraries flat; my old Kelley/Pohl is still with me even to this day; but the clarity in documentation was sought. Let me kill the repo on git and try again with a repo matching my json name and so forth
If you get stuck I could try to clone your repo and see if I can get it to run.
First off I’d be delighted for some feed back and help if you are offerig @scruffr;
Here is where I have gotten to.
I renamed the gitrepo : https://github.com/reducedhackers/pn532_i2c_particle
I edited the spark.json and the subsequent .ino and .h files accordingly.
I imported the library from github and selected the example code and tried to verify it.
In the first attempt the library complained
In file included from readtag.cpp:1:0:
This looks like an error in pn532_i2c_particle library. Would you like to create an issue on GitHub to let the author know?
CREATE ISSUE
pn532_i2c_particle/pn532_i2c_particle.h:5:47: fatal error: PN532Interface.h: No such file or directory
#include "PN532Interface.h"
^
So then I tried the following ( because trial and error is as much a learning tool )
In file included from readtag.cpp:1:0:
This looks like an error in pn532_i2c_particle library. Would you like to create an issue on GitHub to let the author know?
CREATE ISSUE
pn532_i2c_particle/pn532_i2c_particle.h:5:47: fatal error: pn532_i2c_particle/PN532Interface.h: No such file or directory
#include "pn532_i2c_particle/PN532Interface.h"
^
In both cased the .h file in question PN532Interface is in the folder PN532 which is a subfolder of the ‘firmware’ folder for the project.
I had some play, but couldn’t get the nested folders to work either, but I’ve created a PR on your repo which flattened the structure and also got rid of some other build errors.
I hope this helps.
1 Like
Thank you for doing that; ive merged back your pull request and will now read through the edits to learn some more.
I guess it may be worth revisiting this with the IDE team at a later date but for now at least we can confirm that two of us have hammered at it for a bit to see what was up.
Thank you for your time.
1 Like
As mentioned in the blurb for my PR this is a work-in-progress as the IDE team is working on a completely new library feature with better integration with GitHub and “one-face” across Build, Dev and CLI.
It should also line up a bit better with the Arduino structure.
Thanks for the assist here; I do seem to be walking into walls with the environment but its all learning for me It looks like my old Library import/update issue is back again as well Strange BuildIDE behaviour
Congratulations @Scruffr right off the bat and exactly as I have it with the Arduino set up I have that PN532 connected with 2 wires and I can read a card; this means the project keeps moving forward !
3 Likes
Congrats to you, I only moved some things around 
1 Like