Home Learning Fixing Wconstants compiler errors

Fixing Wconstants compiler errors

by shedboy71

I recently tried out an example for a DS18B20 temperature sensor. The code example mentioned 2 libraries, so I went forward and downloaded them and imported them into my IDE but was disappointed to see an error like this when I tried to compile my example sketch

error: WConstants.h: No such file or directory

This occurred when I tried to compile my sketch, the reason for this is that these libraries were written in the ‘dark ages' in terms of the Arduino compiler when WConstants.h was supported but since version 1.00 onwards this has not been the case. Never fear as this is easy to fix and improve.

 

The solution is to delete the line in the library header file like

#include “WConstants.h”

and then in the .h header file, add the following in its place

[codesyntax lang=”cpp”]

#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

[/codesyntax]

Using this code, the code will compile, and it will be compatible with Arduino 0023 and 1.0 versions.

 

Share

You may also like