Go Down

Topic: [Solved] Arduino in Atmel Studio 6.2: undef reference to strlen_P in WString.cpp (Read 3179 times) previous topic - next topic

kruim444

Hello everyboy

First, I hope this is the right place to post this question. If not, please move the topic or tell me where I can post it.

Now, here's the short version of my problem: I tried to switch over to Atmel Studio to develop my Arduino project today and got stuck with these two error messages when trying to build the project:

Code: [Select]
undefined reference to 'strlen_P' in WString.cpp at Line 629
ld returned 1 exit status


Some basic information:

  • Arduino 1.5.6-r2

  • Board: Mega 2560

  • Except for the memory which didn't get enabled correctly yet, the whole project compiles, uploads and works just fine when using Visual Studio with Visual Micro.

  • Atmel Studio version 6.2 just installed and updated today

  • My know-how: Couple of years of programming but only half a year with Arduino and C++



To explain why I'm trying to switch to Atmel Studio:
I am working on an SRAM extension (32Kb) for my Arduino Mega 2560 with the external memory interface. And soldering the memory worked well. But to test and use the memory, I found out I probably have to add set some linker options (see here for more info on that). But, as far as I could find out, these can neither be set with the Arduino IDE nor with Visual Studio with Visual Micro (the IDE I have been using the last few weeks). So I asked google and found Atmel Studio. Thinking it might be up for the task. So that's why I'm trying to switch over to Atmel Studio 6.
(And it looked like a good way to learn more about the microcontroller programming along the way.)

Meanwhile I've got almost everything working in the current version of Atmel Studio 6.2. I had to do some minor changes in some of the libraries, but that seems to work. A basic sketch like the blinking example builds and uploads just fine. But when trying to build my own project, using all the libraries, the error messages above appear.

And the strange thing is, there is no "strlen_P" at that line in the file WString.cpp. Not even close to it. Here are line 614-641 of WString.cpp in "Arduino\hardware\arduino\avr\cores\arduino":

Code: [Select]
String String::substring(unsigned int left, unsigned int right) const
{
if (left > right) {
unsigned int temp = right;
right = left;
left = temp;
}
String out;
if (left > len) return out;
if (right > len) right = len;
char temp = buffer[right]; // save the replaced character
buffer[right] = '\0';
out = buffer + left; // pointer arithmetic
buffer[right] = temp; //restore character
return out;
}

/*********************************************/
/*  Modification                             */
/*********************************************/

void String::replace(char find, char replace)
{
if (!buffer) return;
for (char *p = buffer; *p; p++) {
if (*p == find) *p = replace;
}
}


Hoping it would just be a wrong line number, I searched the whole document, and later even the whole project for strlen_P and found 2 occurrences in WString.cpp. Asking Google how to solve this error did give me some ideas but to be honest, most of the tech talk was a bit too much for me. I just tried to replace strlen_P with __strlen_P as mentioned here, playing around with optimization settings of the compiler and replacing the file with a new one in case it was damaged somehow. I did not try removing the strlen_P from pgmspace.h as I couldn't imagine that to solve it and because I couldn't exactly find out what to do.

However the strange thing that remains is: there is no call to strlen_P at the line reported by the error message. And even deleting the code around this line doesn't change the error message. It still complains about line 629. Even if that line becomes something completely different now. I tried like deleting the whole substring method, and it was still complaining about 629.

The problem has to be somewhere else.... I guess.....

I started to try the same project with the same settings in a different version of Atmel Studio (6.1). Until now, with no luck.

I hope I managed to explain the problem well enough and that my english is readable (it's past midnight here in europe and usually that doesn't improve my writing skills). Otherwise just tell me and I'll try to rephrase it. And please let me know in case I should post any more code. I just don't know what other parts could be important...

Any ideas of what I could try next would be very much appreciated. And any idea of how to set those linker options for the external RAM without moving to Atmel Studio is welcome too.

Thanks!


UPDATE 2014-08-03:

  • Just to see what happens, I deleted all contents of WString.cpp, giving me an empty file with one empty line in it. The error stays exactly the same. According to Atmel Studio there still is an error at line 629 in the (now empty) file.

  • I tried to uninstall everything, rebooting and then reinstalling the freshly downloaded Atmel Studio 6.2 build 1153. No changes.


It seems to me, that this is a problem with Atmel Studio rather than the code (as that can even be empty at that line). So I'll probably check the internet again for any similar problems with Atmel Studio. And just in case it still is a problem with the code, I think it's somewhere completely different so I'll try to create a simple file generating the same error.
If anyone has another idea of what to try.....

kruim444

Ok, I found it. Just one of those stupid mistakes one can look for for hours and not see it....  :smiley-roll:

In case anyone ever has the same problem, this is what solved it:
I did include the arduino-core in the compiler settings, but I did not include the files themselves in the project. I know I tried adding Arduino.h but I probably never tried adding WString.cpp or just the whole core folder.

For some reason the any example I built to see which library was the reason for the problem just worked fine. Even without adding the core files to the project. I must have some difference in project configuration or so...

Anyway, the problem is solved and I can continue to work on my project. Thanks to everyone who took the time to read through my lengthy post above!

Go Up