Using u8g2 images on library outputs undefined

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello! Its my first time here posting, i've been searching for this topic for a lot of time and can't get to the solution, so i decided to try and ask, so maybe one of you can help me!

First of all, im using Microchip Studio, programing on C, using an ATmega32, the thing is, i'm trying to use the u8g2 library to put some images in a GLCD. At this moment, if i put the image on main, i dont have any problems, but i'm trying to get a "clearner" look, and because GIMP exports it with Header and source already, i tried to use it, with no good result. Everytime i try it, i get an undefined of the function.

Im sorry, because English is not my first language, and this is really difficult to try and explain it, way worse than any conversation ive had until today.

So, this is whats intereesting on my main:


#include <VA_default.h>
#include <avr/io.h>
#include <u8g2.h>
#include <util/delay.h>
#include <stdio.h>
#include <stdlib.h>

     // config and setup of the LCD goes here, not really usefull right now
int main(void)
{
   
	u8g2_ClearBuffer(&u8g2);
	u8g2_DrawXBMP(&u8g2, 0, 0, VA_DEFAULT_WIDTH, VA_DEFAULT_HEIGHT, VA_default_bits);
	u8g2_SetFont(&u8g2, u8g2_font_t0_12_tf   );
	u8g2_DrawStr(&u8g2, 50, 28, x_value);
	u8g2_DrawStr(&u8g2, 50, 50, y_value);
	u8g2_SendBuffer(&u8g2);
}

And here is my  VA_default.h

 

#ifndef __VA_DEFAULT_H
#define __VA_DEFAULT_H

#define VA_DEFAULT_WIDTH 128
#define VA_DEFAULT_HEIGHT 64

static const unsigned char  VA_default_bits[];

#endif /* __VA_DEFAULT_H */

 

And my default.c
 

#include "VA_default.h"
#include "avr/pgmspace.h"

static const unsigned char VA_default_bits[] PROGMEM= {

//Hex image goes here

};

 

I dont know if this is enough, the thing is that, if i put the image simply on main, i get no error, but when i use this libraries like this, i get:

 

Severity    Code    Description    Project    File    Line
Error        undefined reference to `VA_default_bits'    ST7920GLCD_Test    E:\DaRkNeSs\Documents\Universidad\TFG\AVR programing\ST7920GLCD_Test\ST7920GLCD_Test\main.c    304

Error        undefined reference to `VA_default_bits'    ST7920GLCD_Test    E:\DaRkNeSs\Documents\Universidad\TFG\AVR programing\ST7920GLCD_Test\ST7920GLCD_Test\main.c    304

 

two times, also, so, could anyone point me what im missing? thanks!

 

This topic has a solution.
Last Edited: Fri. May 20, 2022 - 09:43 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Remove the static from your VA_default_bits[] definition.

 

Since it is in an external C file the array will not be "global".

 

Purists might get upset.   But I put fonts, images, ... into external H files.   e.g. #include "image.h"

 

This means that the main.c sees the static as if it was part of main.c  i.e. same file scope.

The linker will remove anything it does not need.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello! sorry for the late reply! that was exactly the problem! its working now.

 

Mind you telling me why Purists might get upset with the external H files?

For me its a good way to keep the code simple.

 

Thank you so much!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The convention is :

.H for definitions, declarations, macros, ...

.C, .CPP for executable code.

 

In practical housekeeping terms there is a good argument for large data arrays, image data, font data, ... in separate files.

e.g. in pairs of .H, .C

 

However the Arduino IDE and compiler tools favour data in .H files.   It gets a bit unwieldy with .H, .C pairs.   Especially if you are going to have C, C++ guards too.

 

So I am happy with large data arrays in .H but would still avoid executable code.

 

YMMV.   (I suspect that I have already opened a can of worms !! )

 

David.

Last Edited: Fri. May 20, 2022 - 10:13 PM