Linking of unused file and library with mbed and platformio

Hi all,

I have a platformIO project, I’m trying to understand how pio links binaries with mbed.

If I put a lot of C++ classes in the project (headers in include and implementations in src), but I don’t use them, so my main.c is the following:

#inlcude "mbed.h"

int main() {
    return 0;

I get a .elf file of 13992 bytes.

If I move the classes outside the project (f.e. in a directory tmp outside src and include) and I use the same main file, I obtain a .elf file of 9444 bytes.

Why the linker is linking symbols that I am not using? Is there a way to avoid it?

Ok, this Question is from 2019, and it seems still to be an issue.

Is there a way to avoid it? I have the same problem - more than 100KB unused code.
I’m using Platformio ESP32-Arduino

Can you provide a minimal project that reproduces the problem?