Skip to main content

One post tagged with "cpp"

View All Tags

cpp_flag

· One min read

背景

编译c++ 时候需要了解编译过程

cmake 添加c++ flag

当我们用g++编译一个程序的时候,经常会有些警告或者error。这时候,会弹出对应的警告和error,举例:

error: unused variable 'productSize' [-Werror,-Wunused-variable]

你会看到-Werror,-Wunused-variable , 意思是因为这个选项导致error,其实是我有定义了但是没有使用的变量。

如果我们想关闭,可以添加-Wno-unused-variable 也就是在原来的报错的-W-xxx 改成-Wno-xxx 即可

我们可以在add_compile_options 添加对应的编译flag

    add_compile_options(-Wall -Wextra -pedantic -Werror  -Wno-unused-variable)