Gradle with C++:如何更改编译器选项?

D. *_*sin 1 c++ gradle build.gradle

我开始使用 Gradle 并且刚刚构建了一些东西。构建生成了文件“options.txt”:

-x
c++
-c
-I
/path/to/project/src/main/headers
-I
/path/to/project/src/hello/headers
-m64
Run Code Online (Sandbox Code Playgroud)

他们为我选择编译器选项很酷,但例如我想用 -std=c++17 和 -Wall 和 -Wextra 编译我的东西。那么如何将这些标志添加到 g++ 选项中呢?

D. *_*sin 5

只需在 build.gradle 的 'model' 中添加以下内容:

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