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.