Exclude Arduino library

Hello,

I’m converting all my Arduino projects to PlatformIO. I like the interfaces and it’s very easy to add projects with different libraries. Thanks for that.

No I have a question. I need to exclude the “Arduino.h” library to deactivate the HardwareSerial.h library. I wanna add a Softserial library. Here is the code in the Main.ino:

/******************** Includes ********************/
#include <FastSerial.h>
#include <GCS_MAVLink.h>
#include <EEPROM.h>
#include <EEPROMlong.h>

#include "Vars.h"
#include "MAVLink.h"

//Arduino Standard Library
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "wiring.h"
#endif

The FastSerial.h looks like this:

#ifndef FastSerial_h
#define FastSerial_h

// disable the stock Arduino serial driver
#ifdef HardwareSerial_h
# error Must include FastSerial.h before the Arduino serial driver is defined.
#endif
#define HardwareSerial_h

And the FastSerial.cpp:

//#include "../AP_Common/AP_Common.h"
#include "FastSerial.h"

#if defined(ARDUINO) && ARDUINO >= 100
	#include "Arduino.h"
#else
	#include "WProgram.h"
#endif

Now PlatformIO ignore the second include of “Arduino.h”. So the Arduino library is in use before I can include the “FastSerial.h”. That’s my problem at the moment. Is there a way to change the order:
First: FastSerial.h / Second: Arduino.h

Greetings Fabian

See Redirecting...

@ivankravets Hi Ivan, this is not wokring for me. I tried this before with different typings:

lib_ignore = HardwareSerial.h
lib_ignore = HardwareSerial 

Do you have another idea? :slight_smile:

Hello, wanna push this topic a bit… :wink:

How do you do that in Arduino IDE? Or which build system did you use before?

Hi, with Arduino IDE 1.0.5 and before it worked with this code inside the library FastSerial.h:

#ifndef FastSerial_h
#define FastSerial_h

// disable the stock Arduino serial driver
#ifdef HardwareSerial_h
# error Must include FastSerial.h before the Arduino serial driver is defined.
#endif
#define HardwareSerial_h

Since version 1.6.0 I added this code into the main.ino (to make it work):

//Arduino Standard Library
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "wiring.h"
#endif

It also works with Arduino IDE 1.6.8.

Best regards Fabi

Also, could you try conditional mode of LDF? Library Dependency Finder (LDF) — PlatformIO latest documentation

[env:...]
...
lib_ldf_mode = chain+

Hi, thanks for your answer. I will try it tmr. A bit busy today :slight_smile:

Hi and sorry for the very late reply. I tried different LDF options… no solution.

I also tested:
build_flags = -exclude HardwareSerial.h
build_flags = -L/home/fabian/lib -lFastSerial

Still the same error. I hope you have another trick.

UPDATE:

This option:
build_flags = -include /home/fabian/lib/FastSerial/FastSerial.h'
Returns this error:
ArduLED.ino:459:23: error: cannot convert 'HardwareSerial*' to 'BetterStream*' in assignment

Seems that the original HardwareSerial make problems.
HardwareSerial.h:143:25: note: previous declaration as 'HardwareSerial Serial'
extern HardwareSerial Serial;

Have you tried build_flags = -D HardwareSerial_h ?

Yeah same problem:
# error Must include FastSerial.h before the Arduino serial driver is defined.

Also the same error with these build flags:
build_flags = -D HardwareSerial
build_flags = -D HardwareSerial.h

I can send you the whole source code… if it helps.

Greetings

Have you also tried the ivancravets
build_flags = -D HardwareSerial_h
where he uses an underscore

Hi, yes same error with underscore h.