Having gradle compile with g++ and not gcc

Hi all,

I have a project that will not compile with gcc, whether or not that’s a good thing…it does compile with g++ and works just fine. I can’t seem to find much info and telling gradle which compiler to use.

What I have tried is putting this in my build.gradle

   toolChains {
      gcc (Gcc) {                                                                                                     
        path "/user/bin/g++"                                                                                          
      }           
    }  

The result is below, when I type which g++ on the terminal, it points to same path above, but gradle doesn’t like it.

> No tool chain is available to build for platform 'x64': Tool chain 'gcc' (GNU GCC):
    - Could not find C++ compiler 'g++'. Searched in: /user/bin/g++

Is using g++ with gradle possible, and if so what am I doing wrong?
Thanks

Is g++ actually under “/user” and not “/usr”?

That was my mistake @Gary_Hale, g++ is under /usr/bin/g++.
I fixed that in the build.gradle…same result, it just says /usr/bin/g++ now.

> No tool chain is available to build for platform 'x64': Tool chain 'gcc' (GNU GCC):
    - Could not find C++ compiler 'g++'. Searched in: /usr/bin/g++

Which version of Gradle are you using?

The “path” property just adds directories to search for GCC tools.

You can configure each tool the tool chain provides, you just have to configure it for particular platforms. e.g.,

toolChains {
    gcc(Gcc) {
        eachPlatform { tools ->
            tools.cppCompiler.executable = "abc"
        }
    }
}

That configures the C++ compiler to be an executable called “abc” for all platforms. You can target specific ones with target(). See the GCC tool chain documentation. You need to use an action that configures a GccPlatformToolChain.

Thanks @sterling, I’m using gradle 2.1.

I’m fairly new to gradle so this doesn’t really make sense to me yet. So it sounds like I’m defining a new toolChain, and then setting it’s settings?

toolChains {
    gcc(Gcc) {
        eachPlatform { tools ->
            tools.cppCompiler.executable = "g++"
        }
    }
}

Yes, toolChains is a container for ToolChains. By default, Gradle will create some tool chains if none are defined.

So we’re adding a ToolChain of type Gcc named ‘gcc’. Then we’re adding a configuration action that will configure each Gcc tool chain for each platform we can build. eachPlatform() gets a type of NativePlatformToolChain, which lets you configure each ‘tool’ (C++ compiler, linker, etc). Some of this is still in flux and will probably change again.

eachPlatform() was added recently, so you won’t be able to use that in 2.1. NativePlatformToolChain is new too, so I’m not sure you can accomplish the same thing in 2.1 with target(). I don’t remember if we expose the name of the executable as a configurable property in 2.1.

Okay, makes sense now. Thanks for the clarification.

Hi, first thank you for explanation. So I have tried it my-self and I cannot get it to work.

I am getting issue with ‘ccpCompiler’. Seems to be not part of the gcc.DefaultGccPlatformToolChain.

Any chance you know how to make it work ?

thanks