Skip to content

build.extra_flags breaks nested include in a .h file #2041

Closed as not planned
@DaleSchultz

Description

@DaleSchultz

Describe the problem

I have a file called utils.h which I include from my main .ino sketch

utils.h has:
#include <WiFiManager.h>

The app builds fine in Arduino IDE and also with arduino-cli with this command:

arduino-cli compile -b esp8266:esp8266:d1_mini include.ino -e

However if I add a --build-property like this:

arduino-cli compile -b esp8266:esp8266:d1_mini include.ino -e --build-property "build.extra_flags=\"-DSCREEN=64\""

The build fails claiming WifiManager has not been declared:

C:\ard\common\utils.h:887:4: error: 'WiFiManager' was not declared in this scope; did you mean 'WiFiManager_h'?
 11 |    WiFiManager wifiManager;
      |    ^~~~~~~~~~~

I accept that perhaps my utils should be a pair of .h and .cpp files (I have code in the .h file) but it is the case that it all works perfectly without the --build-properties flag.

Here is the minimized utils.h file:

//utils
#ifndef utils_h
#define utils_h
#include "ESP8266WiFi.h"
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
void WiFiMan(char const* APName, int timeout) { // use wifi manager to ask for credentails
	WiFiManager wifiManager;	
} // WiFiMan
#endif  // #ifndef utils

and the include.ino file:

#include "utils.h"  // includes Wifimanager
void setup(){}
void loop(){}

To reproduce

  1. Ensure you have a library such as <WiFiManager.h> installed
  2. Place include.ino and utils.h in a folder
  3. From Windows command prompt, cd to the folder
  4. Issue the command:
    arduino-cli compile -b esp8266:esp8266:d1_mini include.ino -e
    
  5. Note that the sketch compiles OK
  6. Issue the command:
    arduino-cli compile -b esp8266:esp8266:d1_mini include.ino -e --build-property "build.extra_flags=\"-DSCREEN=64\""
    
  7. Note that the build no longer compiles

Expected behavior

I expect the build to succeed with both compile commands.

Arduino CLI version

nightly-20230122 Commit: a58d5ad Date: 2023-01-22T01:33:46Z

Operating system

Windows

Operating system version

11

Additional context

No response

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details

Metadata

Metadata

Assignees

Labels

conclusion: invalidIssue/PR not validtopic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions