" 'font' must be const " compile error

Anything not related to a specific project.

" 'font' must be const " compile error

Postby bronzeman » Sun Dec 13, 2015 6:49 am

This post only serves to provide users with a resolution to the following error. The error occurs when a user downloads the Sparki "standalone" library for use with Linux operating systems, or the standard Arduino IDE on any OS, and attempts to compile a program.

Note: See roboalchemist's reply to this post. His solution is much more efficient than the one I suggest here.

An example compilation error output:

Code: Select all
Robot_Control/glcdfont.c
/usr/share/arduino/libraries/Robot_Control/glcdfont.c:9:23: error: variable 'font' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 static unsigned char  font[] PROGMEM = {


This happens due to the fact that newer versions of Arduino catch and hang on this during compilation.

To resolve the issue:

1) Go to the Sparki library. In my case, it is in Documents\Arduino\Libraries.
2) Open the "Sparki.cpp" file.
3) Go to the line that contains the string " uint8_t font[] PROGMEM = { " It should be located above a 5x7 font table.
4) Change " uint8_t " to " unsigned const int "
5) Save the file.
6) Restart the IDE

This solution worked for me. My programs upload without a hitch.
Last edited by bronzeman on Mon Dec 14, 2015 2:03 am, edited 2 times in total.
bronzeman
 
Posts: 2
Joined: Sun Dec 13, 2015 6:37 am

Re: " 'font' must be const " compile error

Postby roboalchemist » Mon Dec 14, 2015 12:55 am

They did change a bunch of things for 1.6 (generally all better), but it did break some stuff.
But we have a new library that is v1.6 compatible! So use that instead. We just finished it an hour ago, so that's why it wasn't on the main site.
http://download.arcbotics.com/Sparki_Li ... .6.6.1.zip

That said, instead of:
4) Change " uint8_t " to " unsigned const int "
try:
4) Change " uint8_t " to " const uint8_t "
This will save ~2x the memory (arduino ints are 16bit, vs 8bit uint8_t)
---
Joseph Schlesinger - ArcBotics Co-Founder/CTO
roboalchemist
Site Admin
 
Posts: 664
Joined: Mon Jul 16, 2012 3:02 am

Re: " 'font' must be const " compile error

Postby bronzeman » Mon Dec 14, 2015 2:01 am

Thanks, I didn't know that! And the new library works like a charm. :D
bronzeman
 
Posts: 2
Joined: Sun Dec 13, 2015 6:37 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 5 guests