Ignoring libraries in WebIDE

Is it possible to ignore library files in the WebIDE at compile time?

I have two Xenons running small epaper displays, both are slightly different (one is red, black and white, the other just black and white), so need a different library to drive then. As both are going to perform the same function, I was hoping to decide which library to use with a #define and use the same code for everything else.

#define RBW_PAPER 1
#ifdef RBW_PAPER
  #include "ER-ERM0154-1.h"
  #include "ER-EPM0154-1B.h"

Each of those header files define an object called Epd. When compiling I get the error

ER-EPM0154-1B.cpp:9:0: multiple definition of "Epd::~Epd()"

Even without the defines, if I just use comments:

//#include "ER-ERM0154-1.h"
#include "ER-EPM0154-1B.h"

I get the same error. If I delete the two files I’m not using for ER-ERM0154-1.h, it compiles fine.

Is there a way I can say ‘completely ignore ER-ERM0154-1.h’? It looks like although I have not included it, it tries to compile it then finds two definitions for Epd and errors.

Hi there @DaveH thanks for the question!

It is possible to ignore files at compile time, yes. I was just able to get this simple sample to compile in the Web IDE:

#ifdef FOO
    #include "foo.h"
    #include "application.h"

void setup() {}

void loop() {}

foo.h does not exist, application.h does. If I #define FOO 1 I get an error, but do not if I run the code exactly as above.

I suspect your multiple definition error is coming from somewhere else. One way to fix this would be to put something like this at the top of your header files:

#ifndef ER_EPD
  #define ER_EPD

  /* header code */

Try that and let me know how it goes!

1 Like

Thanks for the suggestions. I have played around with this for a bit and I can’t get it to work. Even with the ifdef, else, I seem to either get both libraries or neither, which does not make much sense.

While I have been struggling to get this to compile, I have thought of a few other features & hardware I want to add to one of the two devices, so I think I’m going to fork the project anyway, otherwise it is going to get far too complicated!

Can you provide a shared version of your WebIDE project that I can take a look at?

Sorry, I have been struggling for time to come back to this. I have put together the following project to just look at the library inclusion. The code should take control of the status LED and show it yellow for 3 seconds, after another 3 seconds it will turn it to blue if we are using the first library and green if we are using the second.

I want to be able to decide which library to use by commenting and uncommenting
#define USEONE 1

Just using the #ifdef in the main file, tries to compile both libraries and I get a conflict as there are two definitions of showRunning(). To prevent this,I have put a #ifdef USEONE in libOne and a #ifndef USEONE in libTwo. With #defile USEONE commented out, this works fine and the LED goes green. However if I remove the comments, to make sure USEONE is defined, it still ignores the libOne and it still goes green, not blue. libOne is still ignored.

It looks like the #define USEONE is only local to the main file. Is there any way I can declare this globally, or am I doing the wrong thing to decide which library to include?

How about namespacing?
e.g. like this
(this link will be invalidated in a week or so)

I have not tested this, but it atleast builds :wink:


Fantastic, that works. Thank you for that. I had not come across namespaces before. That should scale up to the full solution I’m working on.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.