Cpp object files leftovers causing build error

I’ve made a really simple project (windows, gradle 2.6) consisting of a main.cpp (printf-hello-world) and a build.gradle-file and in the same directory the gradle-distribution. I’ve used the custom-layout example:

source {
srcDir "."
include “*.cpp”
}

this works as expected and compiles to an executable with the visual-studio compiler. but if I now change (which is clearly wrong of course) the include-statement to

(star)(star)(slash)(star).cpp

gradle will (correctly) gather also the samples from gradle themself and tries to compile them (some succeed, some will fail with compile errors). now I’m in a state with a not working compilation, but some object-files in the temporary directory.
If I now change the include back to “*.cpp” I will get linker-errors because the old object-files (from the examples) are still used to link my executable resulting in redefined symbol “main”-errors. I would expect gradle to recognize that the object files are not needed anymore and are not used to link them into the final executable.

A clean build will get me into a working build again, but I need to do a clean build.

Is this an expected behavior?

Hey,

would you mind creating a reproducable little test project for this. I suggest to not create that project in the gradle distribution directory as this is not a usual usecase and is not recommended at all for projects

tried to make an really small repo-case, but failed :confused:

created main.cpp with:

#include <stdio.h>
int main(int argc, char ** argv) {
	printf("Hello World\n");
    return 0;
}

and build.gradle with:

apply plugin: 'cpp'
apply plugin: 'c'

model {
	components {
		main(NativeExecutableSpec) {
			sources {
				cpp {
					source {
						srcDir "."
						include "**/*.cpp"
					}
				}
			}
		}
	}
}

and copy gradle-2.6 into directory making this structure:

repocase (directory)
     -> build.gradle
     -> main.cpp
     -> gradle-2.6 (directory)
             -> bin (directory)
             -> docs (directory)
             ...
             -> samples (directory)
             -> src(directory)
             ...

compile this to get compile errors (include-paths not found, multiple main defined). now change include to be:

include "*.cpp"

and do a gradle build and it still fails. now doing a gradle clean and gradle build will result in a working build process.

having gradle as part of the project directory makes sense in our case because we have to support projects for a really long time and may have different tool-versions for different projects. (I’ve not looked at how to fix plugin-versions and other stuff to fixed versions, but that’s on my todo-list)

we’re currently looking into this to check what’s going on. regarding the need for the gradle distribution in your project directory, you should check the gradle wrapper functionality. I think this is a way more elegant way of ensuring your project is using the right gradle version.

cheers,
René

thanks, will look into wrapper functionality…