'How to add '-whole-archive' in gn

I am using gn as my build system, and I want to some target deps another with " -whole-archive", but I found seem no way to do that?

What I need is something like:

clang++ -o libmy.so -Wl,--start-group libA.a libB.a -Wl,-whole-archive libC.a -Wl,-no-whole-archive -Wl,--end-group
  1. libA.a and libB.a in --start-group and --end-group
  2. libC.a in -whole-archive and -no-whole-archive

Thanks

gn


Solution 1:[1]

GN doesn't appear to support this use case. However, try building libC as a source_set instead of a static_library.

https://gn.googlesource.com/gn/+/master/docs/reference.md#func_source_set

A source set is a collection of sources that get compiled, but are not
linked to produce any kind of library. Instead, the resulting object files
are implicitly added to the linker line of all targets that depend on the
source set.

Putting every object file from libC directly on the link line has the same effect as using -Wl,--whole-archive.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Charles Nicholson