Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 8 months ago.
Compiler error while porting Arduino library
I don't think you'll need to read all the code, it's just the first line (after the compiler stuff) that is giving the compiler error.
Error: Not a class or struct name in "Adafruit_GFX/Adafruit_GFX.h", Line: 10, Col: 29
#ifndef _ADAFRUIT_GFX_H
#define _ADAFRUIT_GFX_H
#include "mbed.h"
//#include "Arduino.h"
//#include "Print.h"
#define swap(a, b) { int16_t t = a; a = b; b = t; }
class Adafruit_GFX : public Print {                        // THIS LINE RIGHT HERE
 public:
  Adafruit_GFX(int16_t w, int16_t h); // Constructor
  // This MUST be defined by the subclass:
  virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
  // These MAY be overridden by the subclass to provide device-specific
  // optimized code.  Otherwise 'generic' versions are used.
  virtual void
    drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
    drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
    drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
    drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
    fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
    fillScreen(uint16_t color),
    invertDisplay(bool i);
  // These exist only with Adafruit_GFX (no subclass overrides)
  void
    drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
    drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
      uint16_t color),
    fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
    fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
      int16_t delta, uint16_t color),
    drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
      int16_t x2, int16_t y2, uint16_t color),
    fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
      int16_t x2, int16_t y2, uint16_t color),
    drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
      int16_t radius, uint16_t color),
    fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
      int16_t radius, uint16_t color),
    drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
      int16_t w, int16_t h, uint16_t color),
    drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
      uint16_t bg, uint8_t size),
    setCursor(int16_t x, int16_t y),
    setTextColor(uint16_t c),
    setTextColor(uint16_t c, uint16_t bg),
    setTextSize(uint8_t s),
    setTextWrap(bool w),
    setRotation(uint8_t r);
#if ARDUINO >= 100
  virtual size_t write(uint8_t);
#else
  virtual void   write(uint8_t);
#endif
  int16_t
    height(void),
    width(void);
  uint8_t getRotation(void);
 protected:
  const int16_t
    WIDTH, HEIGHT;   // This is the 'raw' display w/h - never changes
  int16_t
    _width, _height, // Display w/h as modified by current rotation
    cursor_x, cursor_y;
  uint16_t
    textcolor, textbgcolor;
  uint8_t
    textsize,
    rotation;
  bool
    wrap; // If set, 'wrap' text at right edge of display
};
1 Answer
11 years, 8 months ago.
Ok so I figured its because I commented out Print.h from the Arduino library. Does mbed have a similar library?
Of course if I just import Arduino's Print.h, it will need 3 more files, which in turn will need 10 more files and so on...
Hello Tony Otis,
what does Print class define? That's the question. There's no print class as I am aware of, at least in mbed sources. Can be though ported by another user. Is this print class https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/Print.h ?? If yes, just remoe that inheritance, printf will be retargeted to default uart on your board, should not cause any problems.
Regards, 
0xc0170
However then he can't use printf with his display ;).
On mbed the almost equivalent is probably Stream, it works without inhereting anything, but then you can't use [name].printf to write to your display. Only of course Stream requires different methods to write to the display:
Copy-pasting from one of my own what you need to implement:
    virtual int _putc(int c);
    virtual int _getc() {
        return 0;
    }
You need to implement getc and putc, since you cannot read from a display, _getc is implemented simply with return 0. I *think* _putc is the equivalent of write in that code. So you need to replace write everywhere with _putc, and it should work.
posted by 05 Mar 2014