c++buildgn

How to add prebuilt/precompiled *.o object files to executable in GN


I have a prebuild object done by 3rd party library, I need to add it to the final executable build by GN.

Is any way to add prebuild object that source is missing directly to GN executable target?

I see GN has precompioed_source, but seems to be linked to precompiled_header and not what I'm looking for.

The GN toolchain's tool link seems to be restrictive to add custom variables.

I can link into a static library manually, but this is not ideal.


Solution

  • Ok, seems it is enough just to add object file to sources. GN does a hard match by file extensions with specific tool, so if object file has a different extension (e.g. not libfoo.o for POSIX), then best is to use copy action to correct the object extension.

    The answer was provided by gn-dev in https://groups.google.com/a/chromium.org/forum/m/#!topic/gn-dev/IbYWe4_nbcc

    I hope it will help others.