Have a cc file listed twice in your gn file. GN produces this nice error:
ERROR at //path/to/BUILD.gn:1:1: Duplicate object file
static_library("MyLib") {
^--------------------------
The target //path/to/MyLib:MyLib
generates two object files with the same name:
obj/path/to/MyLib:MyLib/MyLib.file.o
It could be you accidentally have a file listed twice in the
sources. Or, depending on how your toolchain maps sources to
object files, two source files with the same name in different
directories could map to the same object file.
In the latter case, either rename one of the files or move one of
the sources to a separate source_set to avoid them both being in
That's great. However, that's done _after_ writing the duplicate .o files to the ninja file (https://cs.chromium.org/chromium/src/tools/gn/ninja_binary_target_writer.cc?type=cs&sq=package:chromium&l=336 -- WriteSources() called before CheckForDuplicateObjectFiles(obj_files)), so the next time we try to build ninja then errors out with
ninja: error: obj/path/to/MyLib.ninja:40: multiple rules generate obj/path/to/MyLib:MyLib/MyLib.file.o [-w dupbuild=err]
Comment 1 by dpranke@chromium.org
, Apr 25 2018