Linking native executables having transitive dependencies


We’re trying to build some big native c++ project on linux/gcc with ~300 libs and ~500 executables.
Consider executable A depends on library B, and library B depends on library C (for simplicity, consider they are are all from the same project).
When gradle links A with option -l it has also provide -rlink-path= option (and so on for other transitive dependencies). However, gradle doesn’t add -rlink-path option for transitive dependencies.

Solution we have now is to copy all libraries to a single directory once they are built, and add -rlink-path= as linker.args.

May be there is a better solution for that? We use “cpp” plugin to build, and use “lib project:xxx, library:yyy” on cpp source sets to define depencies between libraries and executables.