PlatformIO Community

How to eliminate conflicting symbols - arduinoststm32-maple, MySensors lib

Hello, newbie here
I want to prevent the compilation of a packages/framework* source file

I’m having a link time symbol conflict between a Platformio framework module and a 3rd party Platformio supported library module, they both define premain() and main() thus the link is reporting duplicate symbols.

the Platformio framework module is:

the 3rd party library is MySensors module:

I would like to prevent the processing of the “framework” module, main.cpp, but only for my particular project.

I’m looking for something like a src_filter but targeting a packages/framework file rather than my source directory.

I’ve tried adding the full path to my platformio.ini file but that seems to be ignored. as in:

src_filter = -/home/test/.platformio/packages/framework-arduinoststm32-maple/STM32F1/cores/maple/main.cpp

Can this be done somehow?

The src_filter path is relative to the src folder -

i.e. if I have

and the file I want to exclude is located in

Then going up six levels (including src)

src_filter = ./../../../../../../.platformio/packages/framework-arduinoststm32-maple/STM32F1/cores/maple/main.cpp

seems to work - in as far as preventing the compile failing outright. However, it has presented this as a somewhat troubling link warning!

Linking .pio/build/genericSTM32F103CB/firmware.elf
.pio/build/genericSTM32F103CB/FrameworkArduino/main.cpp.o: In function `main':
main.cpp:(.text.startup.main+0x2): warning: undefined reference to `setup()'
main.cpp:(.text.startup.main+0x6): warning: undefined reference to `loop()'

I think the best solution is the one you’ve found so far… editing framework-arduinoststm32-maple/STM32F1/cores/maple/main.cpp to make premain and main weak … and submitting a PR to in the hope it gets included in the future. And in the meantime you could do an extrascript that patches main.cpp automatically…

But I am also puzzled as to why it fails with STM32, but not the AVR framework… even though it seems as if the same clash should happen, as main is also defined in the core, and isn’t weak… needs further investigation!

@pfeerick After I looked closer I too ran across the same undefines you mentioned. I think it was due to the format of the src_filter =
I’m still trying to understand the format/scope of src_filter but I believe it should be .

 src_filter = +<*> -<your file to be ignored here>

Without the +<> the local src/ files were being ignored, which I think is the cause of the undefines.
(looking at compile output from “pio run -v”),

So I my above src_filter really should be, I guess…

    src_filter = +<*> -</home/test/.platformio/packages/framework-arduinoststm32-maple/STM32F1/cores/maple/main.cpp>

But still using the full path or the …/…/…/ relative path does not result in main.cpp being ignored.

I believe the reason it works in the Arduino IDE is that the STM32 code is archived into a library before being passed to the linker. We could achieve the same result if we archive main.cpp.o and pass that .a to the linker instead of passing main.cpp.o directly.

The “real” answer probably is to mark those symbols weak, (or maybe archive all the framework code into a library as is done in the Arduino IDE environment??? )

but I wanted to see if there was a way to ignore the framework file from within an individual Platformio project before I get with the Arduino_STM32 folks.

derp… yeah, I wasn’t really paying attention there… was I? :man_facepalming:

Right, so correcting that to be the correct syntax… leads us back to square one… so that didn’t achieve much!

re, archiving into a library… wouldn’t that also affect the atmelavr framework? I’m curious as to why lib_archive = no (as to the default of yes) isn’t changing anything then… (unless, of course, weak symbols are used, as it needs to be no for that to work)… something else going on here, or am I confusing the terms?

I’m going to have to go somewhat silent here as I know not of which I speak. I’m totally new to the Platformio environment so have no clue as to how all this is put together. (the mud is clearing but only a bit)
Agree on the square one…
re archiving, that main.cpp is archived in the plain old Arduino IDE environment builds (non Platfomio builds). I was just thinking that archiving it here may work but I don’t know the implications or how it might be done, just might be a possible solution. I don’t have a clue re “lib_archive = no” or its implication.

Hoping someone knowledgeable will chime in and confirm we cannot “ignore” a “framework” source file from a project platformio.ini src_filter entry. In which case I can go to the Arduino_STM32 folks with a bit of knowledge that it must be tweaked in their code or the Platformio build process for Arduino_STM32 must handle it if archiving is a possible solution,

I’ve opened an issue on the platformio-ststm32 platform issue tracker so this doesn’t get missed… maybe we’ll figure it out there :wink:

@pfeerick, thanks. probably has been beat to death enough here…

1 Like