chipKIT® Development Platform

Inspired by Arduino™

Calling a library from within a library

Created Wed, 23 May 2012 17:55:35 +0000 by Verdris


Verdris

Wed, 23 May 2012 17:55:35 +0000

Hi all; I hope this is the right board for this question.

I'm writing a library for Analog's AD5175 digital potentiometer, and it needs the Wire library. I tried writing #include <Wire.h> into the AD5175 library, but when I try to compile the code, it tells me that Wire.h doesn't exist, no such file or directory.

Is there a particular path I need to write in to the #include statement to specifically locate the Wire library?

Thanks.


Ryan K

Wed, 23 May 2012 19:21:32 +0000

Hello,

Try

#include "Wire.h"

Best Regards, Ryan K Digilent


Verdris

Wed, 23 May 2012 19:45:28 +0000

Hello, Try #include "Wire.h" Best Regards, Ryan K Digilent

That shouldn't make a difference, and when I tried it, indeed it didn't. I still get

fatal error: Wire.h: No such file or directory"

I'm writing this in to the .h file, not my sketch.


Ryan K

Thu, 24 May 2012 22:21:35 +0000

Hello,

Hm, some people have had issues with includes when the paths are incredibly long (due to the fact that the MPIDE root directory is far down in the tree. Have you tried placing it in C: directly? I'm just throwing ideas out there, I have not seen this problem personally. If you give me more information about your system configuration including where MPIDE is installed, OS, etc. I can try to recreate the problem and find a solution for you.

Best Regards, Ryan K Digilent


Verdris

Fri, 25 May 2012 17:07:37 +0000

Hello, Hm, some people have had issues with includes when the paths are incredibly long (due to the fact that the MPIDE root directory is far down in the tree. Have you tried placing it in C: directly? I'm just throwing ideas out there, I have not seen this problem personally. If you give me more information about your system configuration including where MPIDE is installed, OS, etc. I can try to recreate the problem and find a solution for you. Best Regards, Ryan K Digilent

It's a standard installation on a Win7 x64 machine. MPIDE is in C:\Program Files (x86)\mpide-0023-windows-20120304-test and my custom libraries are in C:\Users\USERNAME\My Documents\mpide\libraries.


KurtE

Sat, 26 May 2012 13:19:35 +0000

It was probably only a week ago that I was reading through some different tutorials or maybe Arduino cookbook, or the like and this was covered. I did a quick look to see if I could find the reference again, but if I find it, I will post.

What it more or less said that if your library needs to reference a different library, that you could not handle it directly in your library, but instead must make sure the needed library is first referenced in your sketch...

What I was trying to figure out when I read this, was there ways to override header files. What I was hoping for was for example lets take HardwareSerial. On a Mega it defines all 4 USARTS regardless if we want all 4. So what I was experimenting with, was could you have some simple header file, like: HardwareSerialConfig.h which defined which ones you wanted (or excluded) and could you define a default header defined, that a sketch could overwrite? Sorry for the diversion, but then again it helped me remember where I saw the information.

http://code.google.com/p/arduino/wiki/BuildProcess - Look under compilation.

Hope that helps Kurt


Verdris

Tue, 29 May 2012 15:32:20 +0000

It was probably only a week ago that I was reading through some different tutorials or maybe Arduino cookbook, or the like and this was covered. I did a quick look to see if I could find the reference again, but if I find it, I will post. What it more or less said that if your library needs to reference a different library, that you could not handle it directly in your library, but instead must make sure the needed library is first referenced in your sketch... What I was trying to figure out when I read this, was there ways to override header files. What I was hoping for was for example lets take HardwareSerial. On a Mega it defines all 4 USARTS regardless if we want all 4. So what I was experimenting with, was could you have some simple header file, like: HardwareSerialConfig.h which defined which ones you wanted (or excluded) and could you define a default header defined, that a sketch could overwrite? Sorry for the diversion, but then again it helped me remember where I saw the information. http://code.google.com/p/arduino/wiki/BuildProcess - Look under compilation. Hope that helps Kurt

As a counterexample, take LiquidCrystal_I2C. That library calls

#include &lt;Wire.h&gt;

and

Wire.begin()

from within the library, and works fine.


KurtE

Wed, 30 May 2012 12:52:45 +0000

Don't know, just reporting what I saw. When I looked up your example: I found that while, their header file does include wire.h... When I looked at their test program (http://arduino-info.wikispaces.com/LCD-Blue-I2C)I saw:

*-----( Import needed libraries )-----*/
#include &lt;Wire.h&gt;
#include &lt;LiquidCrystal_I2C.h&gt;

So my guess is that to get their program to work you probably need to Import the Wire library as well as Import the LiquidCrystal_I2C library.

Kurt


Machine_2

Thu, 03 Dec 2015 22:32:06 +0000

Hi, I know this is pretty old but I just wanted to let you guys know that on the latest version, Mpide 0150, this problem is still present. However you can solve it, as previously mentioned, by importing the library in your sketch before importing your own library.

Let's say I have my own library wich needs the DSPI library, so I have the next line inside "myLibrary.h"

#include &lt;DSPI.h&gt;
/*
*Library code
*/

And my sketch looks like this

#include &lt;myLibrary.h&gt;
/*
*Sketch code
*/

This would prompt the message

fatal error: DSPI.h: No such file or directory

To solve it you just need to add "DSPI.h" before "myLibrary.h" in your sketch and your library doesn't need to be modified

#include &lt;DSPI.h&gt;
#include &lt;myLibrary.h&gt;
/*
*Sketch code
*/

This should solve the problem. Given that you have correctly added your library to mpide of course.

Hope this helps :)


majenko

Thu, 03 Dec 2015 22:35:12 +0000

Or just don't use MPIDE. UECIDE has supported nested libraries for years, and the latest Arduino IDE (with chipKIT-core installed) I think can do it too.