#defines across source files

So without testing the code:

  • If main.cpp is compiled, the definition of MQTT_MAX_PACKET_SIZE in main.h will be effective in PubSubClient.h.
  • However, PubSubClient.h is included by other files as well, e.g. PubSubClient.cpp. So if PubSubClient.cpp is compiled, main.h is not part of the compilation and the definition is not effective.
  • I haven’t seen the error message, but I guess you’ll find that it’s a message from compiling PubSubClient.cpp and is not related to main.cpp.

To proceed:

  • Remove the definition from main.cpp.
  • Instead add the following lines to platformio.ini:
build_flags =
    -D MQTT_MAX_PACKET_SIZE=256
3 Likes