C/C++ library definition clashes

From my little knowledge in C/C++ I have a feeling the error messages I’m getting are to do with definition clashes between two or more libraries; namely Arduino.h and StandardCplusplus.h, in my case. Would anyone have answers to any of these questions?

  1. Is my theory on the right track?
  2. If so, is PlatformIO Library Manager not capable of detecting these clashes yet?
  3. Is there a way I can fix this manually?

Here is the error message:
In file included from src\safelock.cpp:1:0:
.pioenvs\leonardo\StandardCplusplus_ID572/cstdlib:60:18: error: expected unqualified-id before 'long'
inline long abs(long i){
^
.pioenvs\leonardo\FrameworkArduino/Arduino.h:86:18: note: in definition of macro 'abs'
#define abs(x) ((x)>0?(x):-(x))
^
.pioenvs\leonardo\StandardCplusplus_ID572/cstdlib:60:18: error: expected ')' before 'long'
inline long abs(long i){
^
.pioenvs\leonardo\FrameworkArduino/Arduino.h:86:18: note: in definition of macro 'abs'
#define abs(x) ((x)>0?(x):-(x))
^
.pioenvs\leonardo\StandardCplusplus_ID572/cstdlib:60:18: error: expected ')' before 'long'
inline long abs(long i){
^
.pioenvs\leonardo\FrameworkArduino/Arduino.h:86:18: note: in definition of macro 'abs'
#define abs(x) ((x)>0?(x):-(x))
^

Sorry if this is the wrong place to go about asking, I’m hoping this will help anyone else with these problems!

We are currently discussing this library. See

1 Like

Hi @kevbot looks like you’re right, take a look at the similar issues in the library repository:

1 Like

Thanks for that @valeros and @ivankravets, I’ll try keep up to date with changes and add a solution to this thread if I find a temporary fix :slight_smile:

Guys, we don’t have time to support this library. I see that the repo of the library is inactive. We propose someone to fork it and apply all PRs that still wait for that. Then we will transfer library.json to the new repo or you can use the current config
https://raw.githubusercontent.com/ivankravets/StandardCplusplus/patch-1/library.json

1 Like

I have just managed to use StandardCplusplus.h with Arduino.h together by applying a solution mentioned in one of the linked issues. Although the automatic compiler still says StandardCplusplus.h: No such file or directory, the following test program worked fine (using Arduino Leonardo):

#include <StandardCplusplus.h>
#include <vector>
#include <Arduino.h>

std::vector<int> ints = {1000, 5000};

void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
delay(ints.at(1)); // should wait for 5 seconds
digitalWrite(13, LOW);
}

The key was adding the extra includes before Arduino.h to eliminate the clash

It’s enough to undefine abs with: #undef abs.
Put this line before #include <vector> for example.

That’s all what is in StandardCplusplus.h.