-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using PSTR and PROGMEM string with template class causes section type conflict #3369
Comments
I found the first one, but I'm not sure i follow. As long as i don't use the debug define it works. so it can link even when the progmem is used inside a templated class. or is that where the second one enters the picture and you can't use PROGMEM and FPSTR inside same file? |
Ok got it to work. Need to move the implementation of the PROGMEM string from the .h file to a .cpp file, and extern it in the header. Then it compiles fine. in .h: namespace ESPmanagerinternals {
extern const char key_networks[];
} in .cpp const char ESPmanagerinternals::key_networks[] PROGMEM = "networks"; |
I have recently encountered this problem and I may have a solution. 😄 BackgroundThe background of my issue is that, I have been using custom debug logging macros, something like:
I have so many of them and the string literals starts to eat up the RAM, obviously transit to PROGMEM is the solution.
to
And I encountered the infamous error "pfmt causes a section type conflict with pfmt", because I have debug logs in both "regular" functions and template functions. The solution of extracting each and every log string into a global static variable is not acceptable to me - not only too much transitional effort, but also increase the maintenance overhead and reduce the usability. (Imagine the scenario you see a debug log line, and wants to look at the relevant code. With inline string you just do a single search. With extracted variable, you first find the variable, and you have to search the variable name again to locate the source...) ReasoningThe post here gave me an idea of the root cause, and then I dug out "eagle.app.v6.common.ld" with an interesting line:
The
SolutionSo I tried the following:
And for all debug log states in template method I switched from:
to
And the code compiles and runs perfectly fine! 😆 |
The bug referenced in the code that required a custom macro to enable PSTR/PROGMEM compilation ( esp8266#3369 ) was fixed a while back and all PROGMEM references now live in their own save .sections. This patch simply is the output of `sed -i s/PSTR_LEA/PSTR/g *` and `sed -i s/PROGMEM_LEA/PROGMEM/g *` on the codebase and the removal of those defines.
The bug referenced in the code that required a custom macro to enable PSTR/PROGMEM compilation ( #3369 ) was fixed a while back and all PROGMEM references now live in their own save .sections. This patch simply is the output of `sed -i s/PSTR_LEA/PSTR/g *` and `sed -i s/PROGMEM_LEA/PROGMEM/g *` on the codebase and the removal of those defines.
Using latest git and arduino IDE.
I use PROGMEM strings and a debug define that places debug messages into progmem, however this does not seem to work when combined with templated classes.
The error is the same as this issue: #2078
i define my debug as
and a const char as
Individually they both compile. i.e. if the debug define is enabled but i do not use testString. it works, and vice versa. but if i use both
A full working example can be found here
https://gist.github.com/sticilface/9a6410978d7235a469c1e154c1c4c396
The text was updated successfully, but these errors were encountered: