Pages: [1]   Go Down
Author Topic: Linking .h files between sketch and a library  (Read 675 times)
0 Members and 1 Guest are viewing this topic.
South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using the v-usb for Arduino library http://code.google.com/p/vusb-for-arduino/.  It contains a keyboard demo which I have copied to my /sketchbook/libraries folder.  This compiles no problem.  My only problem is that there is a usbconfig.h file that ships with the library that in my opinion should actually sit with the user sketch, since this file needs to be configured per sketch in principle.  My problem is that the sketch doesn't compile if I copy the usbconfig.h file from the library folder into the sketch folder.  The error I then get is: /sketchbook/libraries/UsbKeyboard/usbdrv.h:13:23: error: usbconfig.h: No such file or directory.  This happens even though I have
Code:
#include "usbconfig.h"
#include "usbdrv.h"
at the top of the sketch.

So my question is how do I correctly separate user configuration from the library folder while maintaining the following sequence of includes:
User sketch #include a library file (usbdrv.h) residing in the libraries folder,  the library file in turn #include a user supplied config file (usbconfig) located in the sketch folder?
Logged

Saskatchewan
Offline Offline
Sr. Member
****
Karma: 15
Posts: 346
When the going gets weird, the weird turn pro. - Hunter S. Thompson
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can work with a library and your sketch at the same time on the ide by using the tabs. Add a tab to your sketch named libname.h and a tab named libname.cpp (where libname is the library you want to work on). You still need to include them in your sketch. I don't know if they will conflict with installed libraries but if it does just delete the installed one. When you add or remove libraries or sketches you have to restart the IDE.

Is that what you were asking?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are two ways to include a header file:
Code:
#include "header.h"
and
Code:
#include <header.h>

Which symbols you use determines where the file is looked for. Experiment on your own to determine which is appropriate for what you want to do.
Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 50
Posts: 1766
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There are two ways to include a header file:
Code:
#include "header.h"
and
Code:
#include <header.h>

Which symbols you use determines where the file is looked for. Experiment on your own to determine which is appropriate for what you want to do.

From a standards point of view, the angle brackets is for system files, and the double quotes is for files local to the project.
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 52
Posts: 1782
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Include the settings file before including the library, however only the library .h will see the contents.
If you are not using template/inline code ( that normally is defined in the header ) you will not have any luck as .cpp files in the libraries are compiled independent of your sketch, so in reality the library .cpp is an object file before your sketch reaches the compiler.
Logged


South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for the replies.  I suspect that pYro_65 is very close to the root of my problem.
Logged

Pages: [1]   Go Up
Jump to: