PrintEx library in source file-> error, in .ino file works

If I #include <PrintEx.h> in the source file it says No such file or directory.

test.ino

#include "header1.h"

void setup() 
{
}

void loop() 
{
  print_stuff();
}

header1.h

void print_stuff(void);

source1.cpp

#include <PrintEx.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

#include "header1.h"


/*-----( Declare objects )-----*/
// set the LCD address to 0x23 for a 16 chars 2 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x23, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address


PrintEx myLCD = lcd;

void print_stuff(void)
{
lcd.begin(16,2);
  
  float a=0.123456;
  myLCD.printf("%.3f", a);
}

Returns:

Arduino: 1.6.5 (Windows 7), Board: "Arduino Nano, ATmega328"

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs C:\Users\Surreal\AppData\Local\Temp\build8485851296209560734.tmp\PrintEx_library_test.cpp -o C:\Users\Surreal\AppData\Local\Temp\build8485851296209560734.tmp\PrintEx_library_test.cpp.o 

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs C:\Users\Surreal\AppData\Local\Temp\build8485851296209560734.tmp\source1.cpp -o C:\Users\Surreal\AppData\Local\Temp\build8485851296209560734.tmp\source1.cpp.o 

C:\Users\Surreal\AppData\Local\Temp\build8485851296209560734.tmp\source1.cpp:1:21: fatal error: PrintEx.h: No such file or directory
 #include <PrintEx.h>
                     ^
compilation terminated.
Error compiling.

But if I put everything in the ino file it works.

What am I doing wrong?

Hi, thanks for giving my lib a try.

When using any library, you must include it in your sketch (.ino) along with in the file where you need it, so the IDE copies it for compilation.

This applies for libraries that use other libraries (Using SD.h implicitly requires SPI.h, etc...).
This is a big annoyance for many, but the dev team is looking at auto dependency support.

The docs are quite limited that I have done so far, please ask if you have any queries regarding the use of PrintEx.

Ok. Thanks very much. Not just the answer, but also for the lib. Hope it won't eat up too much memory. :slight_smile:

Don't have much experience. So this is compiler or environment depended? Will some work if you don't include all your libs in the main file?

dragospuri:
Ok. Thanks very much. Not just the answer, but also for the lib. Hope it won't eat up too much memory. :slight_smile:

Don't have much experience. So this is compiler or environment depended? Will some work if you don't include all your libs in the main file?

It is far less than the standard printf/sprintf methods.

As you have C++11 enabled, you can use my streaming functionality, it produces smaller code than the equivalent using print()/println(), and the printf method will not be included in the code unless used.

Your function can be written like this:

PrintEx myLCD = lcd;

using namespace ios;

void print_stuff(void)
{
lcd.begin(16,2);
  
  float a=0.123456;

  myLCD << precision(3) << a;

}

Don't have much experience. So this is compiler or environment depended? Will some work if you don't include all your libs in the main file?

Its a feature of the Arduino IDE only, it compiles the code in a temp location so it copies everything before compiling.

It only reads includes from the ino file to determine what to copy. If you want to use any library, anywhere, it must be in the ino as well as visible to the file you need to use it (even if the lib is not used directly in the ino).