May be it is good idea for arduino-cli is to accept special files (if found in the sketch source tree) like c_flags, cpp_flags, ld_flags; and use their content for gcc,g++,ld
There were numerous requests for passing flags to a compiler. With *_flags files all these requests will be closed
Unfortunately the Arduino Library Specification doesn't effectively communicate that the ldflags property is only used when compiling precompiled libraries.
There is more information about precompiled libraries here:
You can use the compiler.c.elf.extra_flags property instead of compiler.libraries.ldflags. This property is referenced in the recipe.c.combine.pattern, which is used as the template for the linking command:
Thanks for the reply. No my library is not precompiled. Neither flags works. Even if I put random garbage into platform.local.txt.
Seems like I can not just place my platform.local.txt to the library folder:
(tried libraries/ , libraries/LibraryName/ , libraries/LibraryName/src, tried to rename the platform.local.txt to platform.txt- all was useless)
Introduced in Arduino IDE 1.5.7. This file can be used to override properties defined in platform.txt or define new properties without modifying platform.txt (e.g. when platform.txt is tracked by a version control system). It must be placed in the same folder as the platform.txt it supplements.
From the text above it is absolutely unclear where this file should be put. Previous paragraph says that platform.txt used to override local settings, while next paragraph says platform.local.txt used to override the global platform.txt
Allright, seems like it is not doable in a simple way. Seems like you can't specify LD_FLAGS (as well as C_FLAGS) when compiling library.
Unlikr other Arduino IDE's imperfections, inability to pass compiler/linker flags is a serious disadvantage. The simpliest way (as I see it) is just use files "c_flags", "cc_flags", "ld_flags", "as_flags" if found in the source tree.
If found - simple add their contents to command lines for the compiler, linker and assembler.
There may be special optimization options required for compiling. There may be special warnings enabled (for example, checking arguments of a printf-like function), and so on and so on. Now we can not handle these cases. What if library requires linking with another library? We can't even add "-lm" ;(.
That is correct. This is a platform configuration file. Not a library configuration file. You must put it in the platform in the same folder as the platform.txt file, not in the library.
Another thing to note is that you must restart Arduino IDE (or run the "Arduino: Restart Daemon" command from the "Command Palette") after you make any changes to the platform configuration files (including adding or editing *.local.txt files), as Arduino IDE won't recognize any changes you make while it is running.
Maybe it is an issue for you, but the thousands of other library developers get by without it without any problem.
It is true that, over the years, we have received a significant number of requests for the ability for the user to make global macro definitions in order to configure libraries and platforms for a given sketch project. However, very few library developers have reported needing such a thing for the persistent configuration of the library. This makes me wonder if this is actually an "XY problem", where injecting linker flags via the library configuration is the "Y", but some more achievable solution is available for whatever your true goal is ("X").
The forum helpers might be able to suggest such a solution if you provide a detailed description of exactly why you want to inject linker flags. Your other topic on the subject would be the appropriate place to do that: