Files with identical names in C/C++ source tree are silently excluded from compilation

I’ve ran into a problem that appears when a native build tree contains source files with same name placed in different directories. It appears that Gradle directs compilation output for the whole tree into a single directory and names of the object files come into clash.

Here’s the example tree:

├── build.gradle
└── src
    └── main
        └── cpp
            ├── foo1
            │
 ├── foo.cpp
            │
 └── foo.h
            ├── foo2
            │
 ├── foo.cpp
            │
 └── foo.h
            └── main.cpp

Files ‘foo.h’ and ‘foo.cpp’ under subdirectories ‘foo1’ and ‘foo2’ declare and define functions ‘foo1()’ and ‘foo2()’; both are called from ‘main.cpp’. The build.gradle just defines the executable:

apply plugin: 'cpp'
  executables {
  main {}
}

When ‘gradle mainExecutable’ is called, linker shows undefined reference to ‘foo2()’, even though compilation step went smoothly. Is there a way to solve that without renaming files? It’s not always possible or desirable.

Thanks for the report: I’ve raised GRADLE-2923 for this issue.

Unfortunately I can’t think of a simple workaround, we’ll need to fix the implementation so that different source files with the same name are not mapped to the same object file.