Library.json for mixed C and C++ compilation options?


I am curious if anyone has found a way to pass separate compilation options to gcc and g++ using a library.json file? I thought to use an extraScript, but could not figure out how to do it.

Any ideas?

According to the SCons documentation, which is the underlying build system in PlatformIO, only-C compiler flags are determined by CFLAGS while only-C++ compiler flags are determined by CXXFLAGS.

This is also an exactly documented use case in PlatformIO.

What exactly does not work? What is the current state of your script?

ah, ok I think this line confused me:


But you have a point! I am guessing something along these lines might work?

env.Append(CXXFLAGS=["cppflag1", "cppflag2"])
env.Append(CFLAGS=[ "cflag1", "cflag2"])

You asked about the state of my script, but I don’t have a script just yet. I am trying to get a DSP library to work and it incorporates both C and C++ files, and the output is garbled, so I am just trying to cover all my bases, and I wanted to make sure I copied over the makefile flags properly when I moved the library into platformio.

Thanks for the tip!

Yes exactly. Now of course if have a define that needs to visible to both C and C++ files, CPPDEFINES is of course also correct.

So the library.json would have to have a build attribute which has a extraScript attribute (docs) pointing to a script file in the library folder, and that can then execute that python script. The docs have an example just like that.

Are you sure the base problem is that the C and C++ compiler invocations need to be different to solve this problem, or could be because of something completely different? If you post the full project (or github link) I can have a look at it.

What immediately comes to mind e.g. with DSP libraries on ARM processors are the FPU ABIs with e.g. soft, softfp and hard and the different underlying vector floating point (VPU) type (Demystifying ARM Floating Point Compiler Options - Embedded Artistry), which have to be the same when linking with precompiled libraries, but that’s just a guess.

1 Like

Here is the codebase I am working with.

You were correct that the FPU settings needed to be set to hard, and they were soft by default. I fixed that, but still no dice. also have a post open on the electrosmith forum asking for support. (the library is the DaisySP audio library)

Thanks for your help!

Okay ehm there are quite a few weird things going on there, like

You are using framework = cmsis yet pull in a linker script from Arduino? Is the automatically chosen linker script wrong?

Why is the entire platform-ststm32 repo cloned in the project?

Why is every package cloned in the project? These are sourced from PlatformIO. Are there modifications in them? This also makes the project highly non-portable if these are used, since if you e.g. source tool-openocd from there and it’s the Linux version, it makes it impossible to run on Windows. PlatformIO handles this automatically.

libDaisy contains an entire copy of the STM32H7 HAL as well as the USB and FAT32 middlewares. These would be pulled in automatically if you set framework = stm32cube?

I’ll have a play around with it.

they are cloned in the project because I specified in lines 16-19 of the platformio.ini file, that the packages, lib, libdeps and platforms dir are all in the project dir, instead of in my home directory. I do this for my projects so I can inspect all the code that platformio pulls. If you delete the platforms and packages dir and build, pio will put them back in the same place automatically.

The libdaisy containing the whole HAL is not my doing, that is what libdaisy comes with.

You might be on to something with the framework and the linker script being inconsistent. I’ll try to get it to work with stm32cube as the framework, and see what happens.

fixed it!

You were right that the linker file was incorrect. Actually the linker script that comes with CubeMX is also incorrect, I believe that the Electrosmith folks generated their own linker script that has different memory locations than the default script. The default script diddn’t work, but then when I put in the electrosmith script it worked perfect.

I also switched it from CMSIS to smt32cube framework. I diddnt’ realize stm32cube was a framework in itself, I thought that CMSIS was the name of the stm32cube framework :smiley: learn new things every day :smiley:

Anywho, thank you for your help! A whole new set of synth nerds will now be able to use platformio without having to do all this work!