It’s not as straightforward as the previous’ post answer but I just stumbled into that recently and wrote a post about it you might get some ideas from Using buildFHSEnv for dynamically linked libraries with esphome as example
It’s not as straightforward as the previous’ post answer but I just stumbled into that recently and wrote a post about it you might get some ideas from Using buildFHSEnv for dynamically linked libraries with esphome as example