Remove non user compiler options

Using Gradle 5.2.1 using the c pluging, I was having issues compiling a project.

After investigations under /build/tmp/compileProject I found an options.txt file

Within it i noticed gradle 5.2.1 is adding some options including "-nostdinc’ and some -isystem includes.

Running the gcc command with the flags found in the file, i was seeing the same error as using ./gradlew build. I removed the ‘-nostdinc’ from my gcc command i was able to compile my project.

What I’m struggling with is how do i remove these “non user” args. When I look at the java source i see that my flags are added to the list then these gradle flags based on toolchain.

Any help would be appreciated

You can try to manipulate the C compiler arguments like the following:

toolChains {
    gcc(Gcc) {
        target("some-target-name") {
            cCompiler.withArguments { /* manipulate the arguments here */ }
        }
    }
}

However, the better questions is what are the issue that Gradle is causing for you? Gradle should make the right decision based on the toolchain you are using. Is the -isystem flag supported by your Gcc version? Do you normally require a sysroot to be configured?

We use -nostdinc so that Gradle can be the owner of everything that is passed to the compiler and ensure we don’t miss include or libraries that could affect caching. Could you provide the version of Gcc you are using as well as what runtime are you trying to build for? (Android, embedded system, etc.)

I was originally having an issue converting some makefiles to gradle. Because of hte nostdinc, some include files available to the system PATH weren’t recognized and after digging through the makefile output was able to determine which directories needed to be directly included.

I understand why it operates this way now, and was able to overcome my issue.

I guess I didn’t like there were aspects I couldn’t modify as these were flags that I had no control over.

1 Like

That is a good point. We are trying a much as possible to let Gradle know and control everything about the compilation so that is can take the right decision by default. There are some gap in the modeling which we are trying to identify. If you can share those additional path that you had to add, we could look into to understand if it’s something Gradle missed during his probe or simply some magic the Makefile were doing. It would help us.

It looks to be makefile magic using -C flag to first change to the directory before executing.