Unable to compile external library

Hi,

I'm currently working on a touchscreen project based on Adafruit's GFX library.
My code works fine as long as I keep all functions in the main .ino file. As soon as I put some functions in an external file (.h, .c), I get a compilation error: n:\DVE_SourceCode\JRE_git_workspace\WashmachineTimer\WashmachineTimer\gui.c:19:34: error: unknown type name 'Adafruit_GFX_Button'.

Here is my .h file:

#ifndef _GUI_H
#define _GUI_H

#include <Arduino.h>
#include <Adafruit_GFX.h>


void PrintBtn(Adafruit_GFX *gfx, Adafruit_GFX_Button *btn, uint16_t borderX, uint16_t borderY, uint16_t width, uint16_t height, uint16_t textcolor, uint16_t outline, uint16_t fill, char* text, uint8_t size);

#endif

And this is my .c code:

#include <Arduino.h>
#include <Adafruit_GFX.h>



/*!
 * \def PrintBtn(void)
 * \brief Short Description
 *        Initialization and drawing of a button
 * \callgraph
 *  \callergraph
*/
void PrintBtn(Adafruit_GFX *gfx, Adafruit_GFX_Button *btn, uint16_t borderX, uint16_t borderY, uint16_t width, uint16_t height, uint16_t textcolor, uint16_t outline, uint16_t fill, char* text, uint8_t size)
{
  btn->initButtonUL(gfx, borderX, borderY, width, height, textcolor, outline, fill, text, size);
  btn->drawButton();
}

I also include my .h in the main .ino file:

#include "const.h"
#include "gui.h"

What do I do wrongly? Did I forget any #include?

Thank you very much in advance for your support!

Regards,

Julien

you should include your .h in your main tab

Hi noiasca,

Thanks for your reply.

Of course, I include the .h in my main tab. I updated my post with this as well!

Thanks!

Hi @jmatthey. The Adafruit_GFX_Button type is a class:

https://github.com/adafruit/Adafruit-GFX-Library/blob/1.10.12/Adafruit_GFX.h#L249

class Adafruit_GFX_Button {

Classes are a C++ feature. There are no classes in C. Because you used the .c file extension on your gui.c file, the file is compiled as C language. You can't use this library from a C language file. But you can use it from a C++ language file. If you rename gui.c to gui.cpp, that will cause the file to be compiled as C++.

Thank you @in0. That was my error indeed!

You're welcome. I'm glad if I was able to be of assistance. Enjoy!