1

我使用Clear Linux发行版(由 Intel 制造)来构建一些使用 CMake 的 C++ 项目。我运行cmake命令make。当make构建代码时,会出现一些警告,maybe-uninitialized并且该警告被视为错误,因为 C++ 编译器已使用-Werror选项运行。目前我无法弄清楚该-Werror选项是从哪里添加的。请帮我找。

我发现CXXFLAGSClear Linux 中环境变量的默认值存储在/usr/share/defaults/etc/profile以下位置:

CFLAGS="-g -O3 -feliminate-unused-debug-types -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-
size=32 -Wformat -Wformat-security -m64 -fasynchronous-unwind-tables -Wp,-D_REENTRANT -ftree-loop-distribute-patterns -Wl,-z -Wl,now
 -Wl,-z -Wl,relro -fno-semantic-interposition -ffat-lto-objects -fno-trapping-math -Wl,-sort-common -Wl,--enable-new-dtags -mtune=sk
ylake -Wa,-mbranches-within-32B-boundaries"
FFLAGS="-g -O3 -feliminate-unused-debug-types -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-
size=32 -m64 -fasynchronous-unwind-tables -Wp,-D_REENTRANT -ftree-loop-distribute-patterns -Wl,-z -Wl,now -Wl,-z -Wl,relro -malign-d
ata=abi -fno-semantic-interposition -ftree-vectorize -ftree-loop-vectorize -Wl,--enable-new-dtags -Wa,-mbranches-within-32B-boundari
es "
FCFLAGS="-g -O3 -feliminate-unused-debug-types -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer
-size=32 -m64 -fasynchronous-unwind-tables -Wp,-D_REENTRANT -ftree-loop-distribute-patterns -Wl,-z -Wl,now -Wl,-z -Wl,relro -malign-
data=abi -fno-semantic-interposition -ftree-vectorize -ftree-loop-vectorize -Wl,-sort-common -Wl,--enable-new-dtags "
CXXFLAGS="$CFLAGS -fvisibility-inlines-hidden -Wl,--enable-new-dtags "

如您所见,它尚不包含该-Werror选项。

另一个可以覆盖 CXXFLAGS 的位置是,/etc/profile但它不存在。本地用户~/.profile~/.bashrc也不要覆盖CXXFLAGS.

那么 CMake 从哪里附加额外的 CXXFLAGS 呢?它有一些内置的附加功能CXXFLAGS吗?

我很确定它们不是来自项目本身,因为否则项目开发人员也无法构建他们的代码。在尝试根据 Linux From Scratch 的说明构建 glibc 时,我也遇到了同样的问题。它可能是我使用的 Clear Linux 发行版指定的东西吗?但我怀疑英特尔是否已修复其发行版使用的所有 C/C++ 代码中的所有警告。

4

1 回答 1

1

有时提出问题是自己找到答案的好方法。

实际上CMakeLists.txt在根项目的目录中添加了它:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option -Wall -Wextra -Werror -Wmissing-declarations -std=c++2a -fdiagnostics-color=always")

我刚刚错过了。

于 2020-09-26T16:42:28.830 回答