[Solved] Redefinition of class Message

The compiler is ignoring #ifndef for me (thus causing a “redefinition of class” error), but adding #include "Particle.h" doesn’t fix it. Is there another possible workaround?

Can you post the relevant code (top of the file up to the first function) to make sure the fix covers your use case?


#include "Particle.h"

#ifndef MESSAGE_H_
#define MESSAGE_H_

class Message {


I am calling #include "Message.h" from two different files, and the compiler gives me "Redefinition of class Message", which tells me it’s ignoring the #ifndef.

1 Like

Which 2 files are calling #include "Message.h"? Would you be able to zip and send me your code in a private message? It seems a bit more complex than can be communicated by code snippets on the forum.

Sure, I will send it to you in a PM. Thanks!

I feel dumb, but how do I send a private message?

You can click on the icon with my face and click Message.

Unfortunately there’s no Message link for me… possibly because I just joined the forum?

Hi @eamonford and @jvanier

The Message class is indeed already defined by the system firmware in communication/src/message_channel.h

Try a different name or namespace.

Thanks @bko. That’s right. Message is already defined here https://github.com/spark/firmware/blob/b9ce4a974dd9b900c45f2b3f5d8ba7cb0ebbd088/system/inc/active_object.h#L77

There’s an open issue in the firmware repository to better namespace the global symbols exported by the Particle firmware to reduce the chance of symbol clashes with common words like Message.

Ah, you’re right @bko – changing the name of my class to something else solved the problem. Thanks @bko and @jvanier!