Build_unflags broken?

Hey all!

I’m having some issues using the build_unflags directive. In my case I’m generating code for the STM32F4DISCO, and have the following configuration in a platformio.ini file;

[env:disco_f407vg]
platform = ststm32
framework = spl
board = disco_f407vg
build_unflags = -nostdlib -nostartfiles
build_flags = -lPDMFilter_GCC -L$PROJECT_DIR/lib_ext -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000ULL -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -D__FPU_USED --specs=nano.specs

Despite this, when generating a binary the following linker commands are generated;

arm-none-eabi-gcc -o .pioenvs/disco_f407vg/firmware.elf -Os -Wl,--gc-sections,--relax -mthumb -mcpu=cortex-m4 -nostartfiles -nostdlib -Wl,-T"stm32f405x6.ld" .pioenvs/disco_f407vg/src/cbuf.o .pioenvs/disco_f407vg/src/dsp_wrapper.o .pioenvs/disco_f407vg/src/hw/board.o .pioenvs/disco_f407vg/src/hw/headphone.o .pioenvs/disco_f407vg/src/hw/microphone.o .pioenvs/disco_f407vg/src/hw/stm32f4_discovery.o .pioenvs/disco_f407vg/src/hw/stm32f4_discovery_audio_codec.o .pioenvs/disco_f407vg/src/hw/stm32f4xx_it.o .pioenvs/disco_f407vg/src/hw/system_stm32f4xx.o .pioenvs/disco_f407vg/src/main.o .pioenvs/disco_f407vg/src/printf.o .pioenvs/disco_f407vg/src/systime/systime.o -L/home/stm32dev/.platformio/packages/ldscripts -Llib_ext -L.pioenvs/disco_f407vg -Wl,--start-group -lc -lgcc -lm -lstdc++ -lnosys -lPDMFilter_GCC .pioenvs/disco_f407vg/libFrameworkCMSISVariant.a .pioenvs/disco_f407vg/libFrameworkSPL.a -Wl,--end-group

In other words, the build_unflags directive seems to be ignored for the linker’s script, which is a deal-breaker for me as I really need to modify the linker’s flags.

On a related note, might it be better to separate compiler and linker flags? IE. using something like build_flags_compiler, build_flags_linker, build_unflags_compiler, and build_unflags_linker? It’s possible there are use-cases where someone would want to modify the compiler and linker flags separately =)

Cheers!

I fixed it yesterday

Please try Redirecting...

Does it work now?

PlatformIO Build System automatically understands passed flags and their types. Use Wl, for linker flags.

It’s possible (read: likely) that I’ve made some simple mistake, but after switching to the development version I can’t initialize the workspace using my previous configuration;

stm32dev@stm32dev-VirtualBox:~/Desktop/stm32_project/pio_test$ pio init -b disco_f407vg --ide eclipse

*********************************************************************************************************************************************************************************************************************************************
If you like PlatformIO, please:
- follow us on Twitter to stay up-to-date on the latest project news > https://twitter.com/PlatformIO_Org
- star it on GitHub > https://github.com/platformio/platformio
- try PlatformIO IDE for IoT development > http://platformio.org/platformio-ide
- donate to keep PlatformIO alive! > http://platformio.org/donate
*********************************************************************************************************************************************************************************************************************************************

Please wait while upgrading PlatformIO ...

Platform ststm32
--------
Updating toolchain-gccarmnoneeabi package:
Versions: Current=2, Latest=2      [Up-to-date]
Updating tool-stlink package:
Versions: Current=2, Latest=2      [Up-to-date]
Updating framework-spl package:
Versions: Current=2, Latest=3      [Out-of-date]
Uninstalling framework-spl package:     [OK]
Installing framework-spl package:
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
Updating framework-cmsis package:
Versions: Current=3, Latest=3      [Up-to-date]
Updating framework-mbed package:
Versions: Current=13, Latest=14      [Out-of-date]
Uninstalling framework-mbed package:     [OK]
Installing framework-mbed package:
Downloading  [####################################]  100%          
Unpacking  [####################################]  100%          
Updating ldscripts package:
Versions: Current=21, Latest=21      [Up-to-date]
PlatformIO has been successfully upgraded to 2.10.2.dev0!



The current working directory /home/stm32dev/Desktop/stm32_project/pio_test will be used for project.
You can specify another project directory via
`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.

The next files/directories will be created in /home/stm32dev/Desktop/stm32_project/pio_test
platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-|
src - Put your source files here
lib - Put here project specific (private) libraries
Do you want to continue? [y/N]: y
Error: [Wed Jun 15 13:33:56 2016] Processing disco_f407vg (platform: ststm32, build_unflags: -nostdlib -nostartfiles, board: disco_f407vg, framework: spl, build_flags: -lPDMFilter_GCC -L$PROJECT_DIR/lib_ext -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000ULL -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -D__FPU_USED --specs=nano.specs)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

AttributeError: 'list' object has no attribute 'replace':
File "/usr/local/lib/python2.7/dist-packages/platformio/builder/main.py", line 172:
print json.dumps(env.DumpIDEData())
File "/home/stm32dev/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 224:
return self.method(*nargs, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/platformio/builder/tools/piomisc.py", line 225:
"defines": get_defines(env_),
File "/usr/local/lib/python2.7/dist-packages/platformio/builder/tools/piomisc.py", line 208:
defines.append(env_.subst(item).replace('\\"', '"'))
======================================================================================================== [ ERROR ] Took 0.51 seconds ========================================================================================================

My configuration file is unchanged and identical to the configuration I posted in the first post in this thread =)

Thanks!

Well, I can see how that would work for adding linker flags, but how would I use that to remove linker flags from the default set of flags? (In my case, removing ‘-nostdlib’ and ‘-nostartfiles’)

Please upgrade to PlatformIO 2.10.3

Sorry, I’ve just taken a look at the source code and I see that build_unflag is applied “after base platform” script but before framework script :frowning: See
https://github.com/platformio/platformio/blob/feature/platformio-30/platformio/builder/tools/platformio.py#L59

Have you tried extra_script?

That source listing does explain the behavior I’m getting, (hopefully) knowing the cause of an issue certainly helps when it comes to finding a solution. TBH I really don’t know any python – C and matlab are really all I’m comfortable with – so extra_script isn’t really a reasonable option for me. Is there any chance that there’ll be a bug report generated for this issue and a patch issued at some point?

You are right. This is a bug. Please open an issue here Issues · platformio/platformio-core · GitHub.

Thanks.

Done! And thanks for the help so far =)

Somehow Build_unflags works for me with most flags, but it doesn’t work with -fno-rtti .

2.10.4.dev0

Please provide your platformio.ini. Thanks.

[env:frdm_k64f] platform = freescalekinetis framework = mbed board = frdm_k64f build_unflags = -fno-rtti

I already put the env.ProcessUnFlags(env.get("BUILD_UNFLAGS")) after the framework script in platformio.py, but it´s still broken.

Please re-test the latest Redirecting...

The issue seems resolved for me, thanks! =D