简体   繁体   中英

Gradle with C++: How to change compiler options?

I'm starting to work with Gradle and have just built a couple things. The build generated the file "options.txt":

-x
c++
-c
-I
/path/to/project/src/main/headers
-I
/path/to/project/src/hello/headers
-m64

That's cool that they choose compiler options for me but for example I'd like to compile my stuff with -std=c++17 and -Wall and -Wextra. So how can I add these flags to the g++ options?

Just add the following inside 'model' in build.gradle:

toolChains {
    gcc(Gcc) {
        eachPlatform {
            cppCompiler.withArguments { args ->
                args << "-std=c++17"
            }
            cppCompiler.withArguments { args ->
                args << "-Wall"
            }
            cppCompiler.withArguments { args ->
                args << "-Wextra"
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM