Compilation error with "deepsleep_hal_impl.h": It worked yesterday... but it doesn't today!?

Hey guys,

I’m getting a weird error when trying to compile a sketch in the Particle Build, that uses the MQTT and SparkJson libraries. I say weird, because yesterday I had four working sketches, and today any of them will compile :frowning:

The errors mention a library I’m never seen before, in a folder with the name of the microcontroller (STM32). Have a look at this…

../hal/src/stm32f2xx/deepsleep_hal_impl.h:22:19: error: expected primary-expression before '__attribute__'
 #define retained  __attribute__((externally_visible, section(".retained_user")))
               ^

Any idea of what am I doing wrong?
I checked the code tons of times, and I cannot find the error. Since the same code worked perfectly yesterday, I suspect that it might be an “external” issue… Or am I too dumb to realize of my error??? :open_mouth:

Thanks a lot for your help!
Jaime

Hmm, there may be something going on with the Libraries because I can’t even compile the examples for the MQTT library or SparkJson library.

Can you provide a bare minimum example that generates this deepsleep_hal_impl.h error so we can look into it further? Thanks!

Hmmm…I wonder if those libraries use the retained keyword that we recently added?

please see [Submission] MQTT Library and Sample for a fix.

Looks like the same issue?

Wow, that was fast! Thanks for the quick reaction!
You may find my sketch here: https://drive.google.com/open?id=0B8MA2me0e_7lbTJ6SlpYNkNveEU
(Don’t forget to include the mentioned libraries, they’re already referenced in the code)

It’s just a simple application that sends data from two sensors to our cloud, so we can display it in two widgets later.

Here’s the entire error message…

In file included from ../hal/src/stm32f2xx/platform_headers.h:19:0,
                 from ./inc/application.h:32,
                 from MQTT.cpp:2:
../hal/src/stm32f2xx/deepsleep_hal_impl.h:22:80: warning: 'externally_visible' attribute ignored [-Wattributes]
 #define retained  __attribute__((externally_visible, section(".retained_user")))
                                                                                ^
MQTT.cpp:231:78: note: in expansion of macro 'retained'
 bool MQTT::publish(char* topic, uint8_t* payload, unsigned int plength, bool retained) {
                                                                              ^
../hal/src/stm32f2xx/deepsleep_hal_impl.h:22:80: error: section attribute not allowed for '<anonymous>'
 #define retained  __attribute__((externally_visible, section(".retained_user")))
                                                                                ^

MQTT.cpp:231:78: note: in expansion of macro 'retained'
 bool MQTT::publish(char* topic, uint8_t* payload, unsigned int plength, bool retained) {
                                                                              ^
MQTT.cpp: In member function 'bool MQTT::publish(char*, uint8_t*, unsigned int, bool)':
../hal/src/stm32f2xx/deepsleep_hal_impl.h:22:19: error: expected primary-expression before '__attribute__'
 #define retained  __attribute__((externally_visible, section(".retained_user")))
                   ^

MQTT.cpp:241:13: note: in expansion of macro 'retained'
         if (retained) {
             ^
../hal/src/stm32f2xx/deepsleep_hal_impl.h:22:19: error: expected ')' before '__attribute__'
 #define retained  __attribute__((externally_visible, section(".retained_user")))
                   ^

MQTT.cpp:241:13: note: in expansion of macro 'retained'
         if (retained) {
             ^
make[1]: *** [../build/target/user/platform-6MQTT.o] Error 1
make: *** [user] Error 2

Thanks again!!!
Jaime

PS. Sorry for my broken English! :\

Found the issue after the MQTT library now tries to compile. There is use of the word retained here:

bool MQTT::publish(char* topic, uint8_t* payload, unsigned int plength, bool retained)

which is a reserved keyword now. I just changed this to kept and it compiled. Obviously this is a bit of work to get the owner to update, but we can pretty easily submit a PR to their repo, which I have done here: https://github.com/hirotakaster/MQTT/pull/9 (If you have a github account and wanna go vote that up with a :thumbsup: to increase exposure, please do :wink: )

1 Like

Hey guys,

Sorry that I didn’t post some feedback earlier!

I’m still having problems, same error, no changes… any idea?
Do the libraries need to be re-imported to Particle Build, or it reads them directly from GitHub?

Thanks a lot!
Jaime

As a workaround, if you don’t need the features in 0.4.6, you can revert to 0.4.5 in the IDE (click, “devices” then select your device and click the arrow, which will allow you to select a version.)

We will look at how to make this available as an opt-in so that the keyword doesn’t clash with existing code.

Awesome! It works again :smile:
Thanks a lot guys for the outstanding support!

Cheers,
Jaime

Yep, you need to remove the MQTT library from your app, and re-add it. As you can see here, the version bumped up from v0.2.5 to v0.2.6 as the author merged in my PR and re-imported the library: https://build.particle.io/libs/560f2b631969eb8af1001727/tab/MQTT.cpp

We have a task to search the Particle Libraries for the use of keyword retained so that we can find these issues before you encounter them hopefully! :wink:

1 Like