Hi
Im trying to specify my include directory to the compiler, but adding any flags to arduino-cli using --build-property build.extra_flags results in linker issues, here’s a picture:
In that image i’ve only added the 02 flag for demonstration purposes. But if I add the -I flag, it fails in a similar way. Is there something im missing when it comes to the build process? Can anyone let me know what I’m doing wrong?
Thanks
Sabith
Okay so I figured out the issue, it’s related to this:
opened 03:04PM - 20 Jul 20 UTC
type: enhancement
topic: documentation
criticality: high
topic: build-process
### Describe the request
Establish two sets of standard "extra flags" build p… roperties:
- one set for use by platform developer
- one set for use by the user
These should be clearly documented as being dedicated to the exclusive use by either the platform developer or the user.
The properties proposed here are only arbitrary properties, without any special use by the build system, so no changes would required in the build system. It is only a matter of setting an example for 3rd party platform developers by adding these additional properties to the `platform.txt` files of the official platforms with comments clearly explaining their intent.
Ideally, the properties would be documented in the [Arduino platform specification](https://arduino.github.io/arduino-cli/latest/platform-specification/) as well (https://github.com/arduino/arduino-cli/issues/985).
### Describe the current behavior
Arduino has established a convention of providing "extra flags" properties in [`platform.txt`](https://arduino.github.io/arduino-cli/latest/platform-specification/#platformtxt). These properties are intended to allow the compilation process to be customized by the addition of arbitrary flags in the compilation commands.
For example:
https://github.com/arduino/ArduinoCore-avr/blob/1.8.6/platform.txt#L39-L49
```text
# This can be overridden in boards.txt
build.extra_flags=
# These can be overridden in platform.local.txt
compiler.c.extra_flags=
compiler.c.elf.extra_flags=
compiler.S.extra_flags=
compiler.cpp.extra_flags=
compiler.ar.extra_flags=
compiler.objcopy.eep.extra_flags=
compiler.elf2hex.extra_flags=
```
These properties are referenced in the appropriate compilation recipes in `platform.txt` ([example](https://github.com/arduino/ArduinoCore-avr/blob/1.8.6/platform.txt#L58)).
The empty definitions in `platform.txt` ensure that if the extra flags are not defined elsewhere, the compilation recipes referencing them will still work. Those default empty definitions can be overrriden from any of the other platform configuration files:
- [`boards.txt`](https://arduino.github.io/arduino-cli/latest/platform-specification/#boardstxt)
- [`boards.local.txt`](https://arduino.github.io/arduino-cli/latest/platform-specification/#boardslocaltxt)
- [`platform.local.txt`](https://arduino.github.io/arduino-cli/latest/platform-specification/#platformlocaltxt)
- [`global platform.txt`](https://arduino.github.io/arduino-cli/latest/platform-specification/#global-platformtxt)
or from the command line:
- [`arduino-cli compile --build-property`](https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_compile/#options)
- [`arduino --pref`](https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options)
---
From the comments in the official `platform.txt` files, it seems that `build.extra_flags` is intended to be for the use of the boards platform developer, while the other "extra flags" properties are intended to be for the use of the user (because a platform developer has no need for `platform.local.txt`).
A common use case of these properties for the user would be to add `-D` flags (e.g., https://github.com/arduino/arduino-cli/issues/210#issuecomment-493892258, https://github.com/arduino/Arduino/issues/6344), but there are other uses.
However, platform developers sometimes use these properties in their `boards.txt` file ([example](https://github.com/MCUdude/MightyCore/blob/v2.0.5/avr/boards.txt#L103-L111)). This presents the problem that the user risks inadvertently overriding the flags defined by the boards platform if they use the "extra flags" properties to modify the compilation command ([example](https://github.com/arduino/arduino-cli/issues/2041)).
### Arduino CLI version
N/A
### Operating system
All
### Operating system version
Any
### Additional context
#### Re: Possible Harmful Effect on APIs
On a certain level, this does provide the user the global macro setting capability that has been often requested, and often rejected:
- https://github.com/arduino/arduino-builder/issues/15
- https://github.com/arduino/arduino-builder/pull/29
- https://github.com/arduino/arduino-builder/pull/282
- https://github.com/arduino/arduino-builder/issues/283
- https://github.com/arduino/arduino-builder/issues/354
- https://github.com/arduino/arduino-ide/issues/1837
- https://github.com/arduino/Arduino/issues/421
- https://github.com/arduino/Arduino/issues/2547
- https://github.com/arduino/Arduino/issues/3635
- https://github.com/arduino/Arduino/pull/3717
- https://github.com/arduino/Arduino/pull/3757
- https://github.com/arduino/Arduino/issues/4528
- https://github.com/arduino/Arduino/issues/5084
- https://github.com/arduino/Arduino/issues/5390
- https://github.com/arduino/Arduino/issues/7189
- https://github.com/arduino/Arduino/issues/11108
- https://github.com/arduino/arduino-cli/issues/159
- https://github.com/arduino/arduino-cli/issues/210
- https://github.com/arduino/arduino-cli/pull/1117
- https://github.com/arduino/arduino-cli/pull/1517
- https://github.com/arduino/tooling-rfcs/issues/9
- https://github.com/arduino/tooling-rfcs/issues/22
However, I think this proposal strikes the right balance of:
- Allowing advanced users to do advanced things
- Not exposing standard users to additional complexity that makes the Arduino development software less beginner friendly
- Being very easy for Arduino to implement
The concern has been that allowing users to set global macros will result in library developers unnecessarily using these as part of the API, making that API less beginner friendly (https://github.com/arduino/arduino-builder/issues/15#issuecomment-145558252). However, if the user is required to use a command line interface or create a specially formatted configuration file in a difficult to access location, the average user won't be interested, and so it will only make sense for a library developer to use this feature for advanced, rarely used features of the library (e.g., enable debug output for troubleshooting of the library). We have already had this "extra flags" capability [since 2014](https://github.com/arduino/ArduinoCore-avr/commit/2b9f022eaad0d107b1516c22ac02bdac4977223b), yet I haven't seen it result in any significant incorporation of user set global macros into the user-level API of Arduino libraries.
#### Additional requests
- https://github.com/arduino/arduino-cli/issues/846#issuecomment-1400723208
- https://forum.arduino.cc/t/using-build-property-to-set-optimize-and-define-symbols/1254465
- https://forum.arduino.cc/t/compiler-option-defines-overriding-esp32-and-not-compiling/990862
- https://forum.arduino.cc/t/how-to-add-compile-options-to-arduino-ide-1-8-13/692640/3
- https://forum.arduino.cc/t/ide-to-command-line-build-support-d/682481/3
- https://forum.arduino.cc/t/what-could-prevent-platform-local-txt-from-being-read/674998
### Issue checklist
- [X] I searched for previous requests in [the issue tracker](https://github.com/arduino/arduino-cli/issues?q=)
- [X] I verified the feature was still missing when using the latest [nightly build](https://arduino.github.io/arduino-cli/dev/installation/#nightly-builds)
- [X] My request contains all necessary details
opened 01:05AM - 23 Jan 23 UTC
closed 05:28AM - 23 Jan 23 UTC
conclusion: invalid
topic: code
type: imperfection
### 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:
```text
arduino-cli compile -b esp8266:esp8266:d1_mini include.ino -e
```
However if I add a `--build-property` like this:
```text
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:
```text
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:
```cpp
//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:
```cpp
#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:
```text
arduino-cli compile -b esp8266:esp8266:d1_mini include.ino -e
```
5. Note that the sketch compiles OK
6. Issue the command:
```text
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
- [X] I searched for previous reports in [the issue tracker](https://github.com/arduino/arduino-cli/issues?q=)
- [X] I verified the problem still occurs when using the [nightly build](https://arduino.github.io/arduino-cli/dev/installation/#nightly-builds)
- [X] My report contains all necessary details
Is there any way I can add extra build flags when compiling on your platform?
beegee
(Bernd Giesecke)
August 1, 2024, 11:12am
3
This is more a questions towards the Arduino-CLI community and not to us, but I can show how I am adding compiler flags:
When using Arduino-CLI I am adding extra flags like this:
.\Windows\arduino-cli.exe compile -b rak_rui:stm32:WisDuoRAK3172EvaluationBoard --build-property compiler.cpp.extra_flags="-DMY_DEBUG=1 -DAUTO_DR=1" --output-dir .\RUI3-Modular\flash-files --build-path .\RUI3-Modular\build --build-cache-path .\RUI3-Modular\cache --no-color --verbose --library .\RUI3-Modular\libraries .\RUI3-Modular\RUI3-Modular.ino
I have to put the flags into ""
--build-property compiler.cpp.extra_flags="-DMY_DEBUG=1 -DAUTO_DR=1"
system
(system)
Closed
August 11, 2024, 11:13am
4
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.