Home › Forums › Sparkfun MP3 Shield Library Support Forum › compile error: variable ‘bitrate_table’ must be const
Tagged: compiling
- This topic has 16 replies, 3 voices, and was last updated 8 years, 11 months ago by Michael P. Flaga.
-
AuthorPosts
-
February 15, 2013 at 9:47 am #2125AnonymousInactive
Hi All,
I have been searching for an answer on the problem I ran in to but I could not find it in this forum, and not on Internet (perhaps I did not search well enough).
Anyways, Perhaps I am the first to run into this problem. When I compile the example programs for the MP3 shield (source: http://www.billporter.info/2012/01/28/sparkfun-mp3-shield-arduino-library/ ) I get this error message:
SFEMP3Shield.cpp:25:37: error: variable ‘bitrate_table’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
I sort of understand it, but I do not know how and where to solve this. Also, I can not understand why I run into this problem and nobody else has reported this.
I run Arduin IDE 1.0.1
I use a Arduino UNO
I use the MP3 player shield from Sparkfun
OS: Ubuntu 12.10 64-bit
I have all the libraries (SdFat + SFEMP3Shield) (source: https://github.com/madsci1016/Sparkfun-MP3-Player-Shield-Arduino-Library/archive/master.zip) installed in:
/usr/share/arduino/libraries/z
Can anybody help me or point me in the right direction?
Cheers,
Mikel
February 15, 2013 at 10:41 am #2126Michael P. FlagaMemberI am not 100%, but I believe your problem is the version of avr-gcc. My google foo finds this issue with newer versions of avr-gcc, than I think what is found in the Arduino IDE. I am running windows with 1.0.3 and likewise did not have problems with 1.0.1. or 1.0.2. Which uses avr-gcc 4.3.2 It looks like at least 4.7.0 and greater may have this issue.
Try replacing the line SFEMP3Shield.cpp:25 with
…
– PROGMEM uint16_t bitrate_table[15][6] = {
+ static const uint16_t bitrate_table[15][6] PROGMEM = {
…Also does a “which avr-gcc” show you are using an instance outside that of the Arduino’s IDE?
what is the version of “avr-gcc -v”? (both, if other) to confirm this was the problem.
If the above fixes the issue I can check it in. As it appears to work fine on my version with the proposed change.
Reference: http://code.google.com/p/sdfatlib/issues/detail?id=39
February 15, 2013 at 11:29 am #2131AnonymousInactiveoutput “avr-gcc -v”
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.7.0/lto-wrapper
Target: avr
Configured with: ../src/configure -v –enable-languages=c,c++ –prefix=/usr/lib –infodir=/usr/share/info –mandir=/usr/share/man –bindir=/usr/bin –libexecdir=/usr/lib –libdir=/usr/lib –enable-shared –with-system-zlib –enable-long-long –enable-nls –without-included-gettext –disable-libssp –build=x86_64-linux-gnu –host=x86_64-linux-gnu –target=avr
Thread model: single
gcc version 4.7.0 (GCC)February 15, 2013 at 11:37 am #2137AnonymousInactiveHi Michael,
Thanks for your fast anwer and help, it solved the problem I had, but I got new compilation (linking) erros. I put the compilation messages and errors under this message.
avr-gcc is version 4.7.0 so you where right about the problem
Do you have any idea how to solve the new errors?
Thanks,
Mikel
*************************************************
avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/SPI -I/home/michiel/sketchbook/libraries/SdFat -I/home/michiel/sketchbook/libraries/SFEMP3Shield /tmp/build921403600284632430.tmp/sketch_feb15a.cpp -o /tmp/build921403600284632430.tmp/sketch_feb15a.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/SPI/SPI.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/SdFat/SdFat.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/SdFat/istream.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/SdFat/MinimumSerial.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/SdFat/SdFatUtil.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/SdFat/SdFile.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/SdFat/SdVolume.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/SdFat/ostream.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/SdFat/Sd2Card.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/SdFat/SdStream.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/SdFat/SdBaseFile.cpp.o
avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/SPI -I/home/michiel/sketchbook/libraries/SdFat -I/home/michiel/sketchbook/libraries/SFEMP3Shield -I/home/michiel/sketchbook/libraries/SFEMP3Shield/utility /home/michiel/sketchbook/libraries/SFEMP3Shield/SFEMP3Shield.cpp -o /tmp/build921403600284632430.tmp/SFEMP3Shield/SFEMP3Shield.cpp.o
/home/michiel/sketchbook/libraries/SFEMP3Shield/SFEMP3Shield.cpp: In member function ‘uint8_t SFEMP3Shield::vs_init()’:
/home/michiel/sketchbook/libraries/SFEMP3Shield/SFEMP3Shield.cpp:236:34: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
/home/michiel/sketchbook/libraries/SFEMP3Shield/SFEMP3Shield.cpp: In member function ‘uint8_t SFEMP3Shield::playTrack(uint8_t)’:
/home/michiel/sketchbook/libraries/SFEMP3Shield/SFEMP3Shield.cpp:775:11: warning: unused variable ‘trackNumber’ [-Wunused-variable]
Using previously compiled: /tmp/build921403600284632430.tmp/WInterrupts.c.o
Using previously compiled: /tmp/build921403600284632430.tmp/wiring_digital.c.o
Using previously compiled: /tmp/build921403600284632430.tmp/wiring_analog.c.o
Using previously compiled: /tmp/build921403600284632430.tmp/wiring.c.o
Using previously compiled: /tmp/build921403600284632430.tmp/wiring_shift.c.o
Using previously compiled: /tmp/build921403600284632430.tmp/wiring_pulse.c.o
Using previously compiled: /tmp/build921403600284632430.tmp/Stream.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/HardwareSerial.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/new.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/CDC.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/USBCore.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/main.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/WMath.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/HID.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/Print.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/Tone.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/WString.cpp.o
Using previously compiled: /tmp/build921403600284632430.tmp/IPAddress.cpp.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/WInterrupts.c.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/wiring_digital.c.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/wiring_analog.c.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/wiring.c.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/wiring_shift.c.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/wiring_pulse.c.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/Stream.cpp.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/HardwareSerial.cpp.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/new.cpp.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/CDC.cpp.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/USBCore.cpp.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/main.cpp.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/WMath.cpp.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/HID.cpp.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/Print.cpp.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/Tone.cpp.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/WString.cpp.o
avr-ar rcs /tmp/build921403600284632430.tmp/core.a /tmp/build921403600284632430.tmp/IPAddress.cpp.o
avr-gcc -Os -Wl,–gc-sections -mmcu=atmega328p -o /tmp/build921403600284632430.tmp/sketch_feb15a.cpp.elf /tmp/build921403600284632430.tmp/sketch_feb15a.cpp.o /tmp/build921403600284632430.tmp/SPI/SPI.cpp.o /tmp/build921403600284632430.tmp/SdFat/SdFat.cpp.o /tmp/build921403600284632430.tmp/SdFat/istream.cpp.o /tmp/build921403600284632430.tmp/SdFat/MinimumSerial.cpp.o /tmp/build921403600284632430.tmp/SdFat/SdFatUtil.cpp.o /tmp/build921403600284632430.tmp/SdFat/SdFile.cpp.o /tmp/build921403600284632430.tmp/SdFat/SdVolume.cpp.o /tmp/build921403600284632430.tmp/SdFat/ostream.cpp.o /tmp/build921403600284632430.tmp/SdFat/Sd2Card.cpp.o /tmp/build921403600284632430.tmp/SdFat/SdStream.cpp.o /tmp/build921403600284632430.tmp/SdFat/SdBaseFile.cpp.o /tmp/build921403600284632430.tmp/SFEMP3Shield/SFEMP3Shield.cpp.o /tmp/build921403600284632430.tmp/core.a -L/tmp/build921403600284632430.tmp -lm
SFEMP3Shield/SFEMP3Shield.cpp.o: In function `_GLOBAL__sub_I__ZN12SFEMP3Shield5trackE’:
/usr/share/arduino/hardware/arduino/cores/arduino/Print.h:43: undefined reference to `sd’
collect2: error: ld returned 1 exit statusFebruary 15, 2013 at 11:40 am #2138AnonymousInactivewarnings & errors:
/home/michiel/sketchbook/libraries/SFEMP3Shield/SFEMP3Shield.cpp: In member function ‘uint8_t SFEMP3Shield::vs_init()’:
/home/michiel/sketchbook/libraries/SFEMP3Shield/SFEMP3Shield.cpp:236:34: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
/home/michiel/sketchbook/libraries/SFEMP3Shield/SFEMP3Shield.cpp: In member function ‘uint8_t SFEMP3Shield::playTrack(uint8_t)’:
/home/michiel/sketchbook/libraries/SFEMP3Shield/SFEMP3Shield.cpp:775:11: warning: unused variable ‘trackNumber’ [-Wunused-variable]SFEMP3Shield/SFEMP3Shield.cpp.o: In function `_GLOBAL__sub_I__ZN12SFEMP3Shield5trackE’:
/usr/share/arduino/hardware/arduino/cores/arduino/Print.h:43: undefined reference to `sd’
collect2: error: ld returned 1 exit statusFebruary 15, 2013 at 3:30 pm #2139Michael P. FlagaMemberI have been poking around with avr-gcc 4.7.0 and find they enforce more and require fixes in the arduino libraries. as per http://andybrown.me.uk/wk/2012/04/28/avr-gcc-4-7-0-and-avr-libc-1-8-0-compiled-for-windows/ . Initially I get an error similar to the above collect2 on sd. , but not the same.
I am not a Linux person, but I am suspicious that your avr-gcc that you are using is not the avr-gcc within/provided by the Arduino Library. It took a lot of effort to discover the subtle tweaks required to get 4.7.0 working fully with this and SdFat’s Library. So you could go forward; by updating the libraries, as per the above link. Or go back to the normally used avr-gcc by Arduino (4.3.0).
Going Forward I found that SdFatUtil.h requires a minor update as to all the FreeRam to work. It is simplest to comment out the Serial.print(FreeRam(), DEC); in the setup(). Until I make an issue with SdFatLib.
February 15, 2013 at 5:30 pm #2141AnonymousInactiveHi Michael,
Thanks for your help again. I have not yet tried your last suggestions, I am going to tomorrow.
How do I find out what avr-gcc version is used under the hood of Arduino? You are suspicious it is not the same version as I see from my terminal?
Thanks,
Mikel
February 16, 2013 at 7:12 am #2142AnonymousInactiveHi Michael,
Haven’t succeeded yet to get it working, thought just let you know.
I do not understand how I can used the (for Windos) compiled libraries that you referred to in your post. Perhaps I should try to downgrade to avr-gcc 4.3.0?
Working on…
Mikel
February 16, 2013 at 7:32 am #2143AnonymousInactiveBTW, I now get the following error when I compile MP3Shield_Library_Demo.ino:
SdFat/SdFatUtil.cpp.o: In function `SdFatUtil::SerialPrintln_P(char const*)’:
/home/michiel/sketchbook/libraries/SdFat/SdFatUtil.cpp:73: undefined reference to `SdFatUtil::__brkval’
/home/michiel/sketchbook/libraries/SdFat/SdFatUtil.cpp:73: undefined reference to `SdFatUtil::__brkval’
/home/michiel/sketchbook/libraries/SdFat/SdFatUtil.cpp:73: undefined reference to `SdFatUtil::__malloc_heap_start’
/home/michiel/sketchbook/libraries/SdFat/SdFatUtil.cpp:73: undefined reference to `SdFatUtil::__malloc_heap_start’
collect2: error: ld returned 1 exit statusWhen I compile the following code:
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>SFEMP3Shield MP3player;
void setup() {
Serial.begin(9600);
//start the shield
MP3player.begin();//start playing track 1
MP3player.playTrack(1);
}//do something else now
void loop() {Serial.println(“I’m bored!”);
delay(2000);}
On compilation of the above code I get the following error:
SFEMP3Shield/SFEMP3Shield.cpp.o: In function `_GLOBAL__sub_I__ZN12SFEMP3Shield5trackE’:
/usr/share/arduino/hardware/arduino/cores/arduino/Print.h:43: undefined reference to `sd’
collect2: error: ld returned 1 exit statusFebruary 16, 2013 at 8:22 am #2144AnonymousInactiveOK I can report some progress on my problem.
I upgraded from Arduino 1.0.1 to version 1.0.3. (manual download from Arduino website).
Now with v1.0.3. the “MP3Shield_Library_Demo.ino” compiles error free!!!! Wohooh!!!
The other simple program (example code from : http://www.billporter.info/2012/01/28/sparkfun-mp3-shield-arduino-library/) still gives a compilation error:
SFEMP3Shield/SFEMP3Shield.cpp.o: In function `SFEMP3Shield::begin()’:
/home/michiel/sketchbook/libraries/SFEMP3Shield/SFEMP3Shield.cpp:100: undefined reference to `sd’So still is a question why the Arduino IDE version 1.0.1 gives me all the problems. Also, how to solve the above compilation error?
Work in progress. If somebody knows please let me know.
February 16, 2013 at 8:52 am #2145AnonymousInactiveHi All,
OK I got all problems solved now!
The example program from http://www.billporter.info/2012/01/28/sparkfun-mp3-shield-arduino-library/
needs to be adapted for Arduino IDE version 1.0.3. The code I got working is:
/code {simple_mp3_example.ino}
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>SdFat sd;
SFEMP3Shield MP3player;
void setup() {
Serial.begin(9600);
//start the shield
// MP3player.begin();
if(!sd.begin(SD_SEL, SPI_HALF_SPEED)) { sd.initErrorHalt(); } // newly required in 1.01.00 and higher
if(MP3player.begin() != 0) {Serial.print(F(“ERROR”)); }//start playing track 3
MP3player.playTrack(3);
}//do something else now
void loop() {Serial.println(“I’m bored!”);
delay(2000);}
/end code {simple_mp3_example.ino}
So conclusion2:
1). MP3 player shield on Ubuntu 12.10 (64-bits) does not work with supplied version 1.0.1 of Arduino IDE. Instead version 1.0.3 needs to be downloaded from Arduino website (http://arduino.cc/en/Main/Software).
2). The simple MP3 player shield code (from website: http://www.billporter.info/2012/01/28/sparkfun-mp3-shield-arduino-library/) needs to be updated to the code written above in this post ({simple_mp3_example.ino}).
Thats all. I hope this also helps other people, as it took be some time to work this all out!
Cheers,
Mikel
February 17, 2013 at 1:07 pm #2147Michael P. FlagaMemberI have updated the above mentioned quick example. As it was typical of prior to 1.2.0
The __brkval and __malloc_heap_start errors are from the avr-gcc 4.7 as I had found that SdFat Lib has issues (and found a fix by tweaking SdFat).
I was not pointing out that a windows solution would help. Where as I found on that web page Andy Brown documents and provides updated Arduino Core Library fixes (near the bottome) that are needed to make avr-gcc 4.7 work.
I note that stock Arduino IDE comes with avr-gcc 4.3 for both 1.0.1 and 1.0.3 (infact all of them) and not 4.7. So installing 1.0.3 simply put the 4.3 back into play. I am not sure how the Linux distro of Arduino places and uses the avr-gcc. So I can not make much comment there, except to say prior to re-installing Arduino IDE you were compiling with an un-supported avr-gcc.
I am glad it is working.
February 8, 2016 at 6:26 pm #3486AnonymousInactiveHi there –
I’m new to some of this stuff, so you’ll have to excuse my ignorance.
I’m trying to run the MP3Shield_Library_Demo, now using Arduino IDE 1.6.7.
I replaced
“PROGMEM uint16_t bitrate_table[15][6] = {”
with:
“static const uint16_t bitrate_table[15][6] PROGMEM = {”in the SFEMP3Shield.cpp..
But now I get these errors:
../Arduino/libraries/SFEMP3Shield/SFEMP3Shield.cpp: In member function ‘uint8_t SFEMP3Shield::vs_init()’:
../Arduino/libraries/SFEMP3Shield/SFEMP3Shield.cpp:293:34: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
if(VSLoadUserCode(“patches.053”)) return 6;
Any suggestions?
February 8, 2016 at 10:14 pm #3488Michael P. FlagaMemberhmm,
I am not able to reproduce your experience with 1.6.6(arduino-nightly.2015_11_02) or with 1.6.7(arduino-nightly.2016_02_02). I cut and pasted your line from above and it compiled successfully.
If you are Linux you may be running a newer version of avr-gcc. In windows the IDE supplies the avr-gcc and for both of the above it is avr-g++ (GCC) 4.8.1, but with linux you may have a more recent version of avr-gcc.
February 9, 2016 at 6:32 am #3489AnonymousInactiveI’m on a Mac. Is there a way to change the version of AVR-GCC? And what version do I want, exactly?
I am using a generic Uno R3 Arduino-compatible board, with the ATMEGA328P + 16U2 MCUs, and a Geeetech V1053B MP3 Shield.
-
AuthorPosts
- You must be logged in to reply to this topic.