How can you specify a custom GCC/G++ compiler location using Gradle's cpp-library and cpp-application plugins?

Viewed 534

We need to specify a custom GCC/G++ compiler location using Gradle's cpp-library and cpp-application plugins. According to the docs tool chain section:

Linux To build on Linux, install a compatible version of GCC or Clang. The C++ plugins will discover GCC or Clang using the system PATH.

Prepending the PATH environment variable with a path to the desired g++ doesn't seem to get picked by Gradle.

How can you direct Gradle to get GCC/G++ from a custom path?

2 Answers

I believe you can add a custom toolchain section to the build.gradle file, something like:

toolChains {
    custom_gcc_toolchain(Gcc) {
        target("<target_platform>") {
            path '<path_to_custom_gcc_folder>'
            cCompiler.executable '<c_compiler_executable>'
            assembler.executable '<assembler_executable>'
            linker.executable '<linker_executable>'
        }
    }
}

Finally found that this worked:

model {
    toolChains {
        gcc(Gcc) {
            path '/custom/path/to/gcc-7.1.0/bin/'
        }
    }
}
Related