Compile Error With Adafruit_GFX.h

My sketch #includes Adafruit_GFX.h that have the following on Lines 12-16
#define adagfxswap(a, b) { int16_t t = a; a = b; b = t; }

  #if !defined(ESP8266)
    #define swap(a, b) adagfxswap(a, b)
  #endif

I am getting the following compile error:

 ```

Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from C:\Users\Acer\Documents\Arduino\libraries\Waveshare_ILI9486\src\Waveshare_ILI9486.cpp:25:0:

C:\Program Files (x86)\Arduino\libraries\Adafruit_Display/Adafruit_GFX.h:12:26: error: expected unqualified-id before '{' token

#define adagfxswap(a, b) { int16_t t = a; a = b; b = t; }
^

C:\Program Files (x86)\Arduino\libraries\Adafruit_Display/Adafruit_GFX.h:15:22: note: in expansion of macro 'adagfxswap'

#define swap(a, b) adagfxswap(a, b)
^

C:\Users\Acer\Documents\Arduino\libraries\Waveshare_ILI9486\src\Waveshare_ILI9486.cpp:742:7: note: in expansion of macro 'swap'

void swap(int16_t &x, int16_t &y)
^

C:\Users\Acer\Documents\Arduino\libraries\Waveshare_ILI9486\src\Waveshare_ILI9486.cpp:743:2: error: expected unqualified-id before '{' token

{

^

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.



The Adafruit library well written and established.  What might be my problem.

Thanks

Sadster

Hello, please make sure that the Adafruit_GFX.h library has been installed properly.

What happens when you compile an example sketch?

Where did you get the library from? That is not from the current version of Adafruit_GFX, and adagfxswap was relocated to the cpp file over seven years ago:
https://github.com/adafruit/Adafruit-GFX-Library/commit/f5ec45e42b7216ca3fa34eb08ec052071d672422

1 Like

Your include syntax is incorrect

Your are most likely correct! The library is indeed from years ago. I will try to get the updated library.

Aha! All worked fine once updated library was installed!

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