使用英特尔 C 编译器避免来自系统包含文件的警告

问题描述

我已经发布了 this original question,但由于它不是与 CMake 相关的问题,所以我将其重新表述:

我有这个例子:

#include <iostream>
#include <string>

int main()
{
        std::string a("Text");

        std::cout << a.c_str() << std::endl;

        return 0;
}

我正在尝试使用以下行与 ICC(icc (ICC) 19.1.1.217 20200306,使用 GCC 4.8、7、8 和 9 作为基础测试)进行编译:

icc -o OUT -pedantic-errors -fmax-errors=1 -march=native -Wall -Werror -Wfatal-errors -Wextra -ftree-vectorize -g -Wl,--exclude-libs,ALL -O3 -DNDEBUG -fPIC -fvisibility=hidden -Wstrict-aliasing -std=gnu++17 main.cpp

但它会触发导致错误的警告(因为 -Werror)。这是使用 GCC 8 gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3) 作为基本编译器时的输出:

icc: warning #10193: -vec is default; use -x and -ax to configure vectorization
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h(5052) (col. 50): error #2102: violation of ansi-alias rules

compilation aborted for main.cpp (code 4)

所以,为了编译,我必须去掉 -Wstrict-aliasing 检查。就像那样,还有一整套其他检查会触发类似的行为(来自系统包含文件的警告)。

我担心的是,我真的很想对我自己的代码进行这些检查,但显然,不是对我无法控制的库进行检查。

建议使用 -isystem-isystem=/opt/rh/devtoolset-8/root/usr/include/c++/8,但这只会修正错误:

icc: warning #10193: -vec is default; use -x and -ax to configure vectorization
/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'

甚至CMake discourages explicitly the use of -isystem on system include files

是否有其他标志可以关闭系统包含文件的警告?

用 gcc (g++) 替换 icc 解决了这个问题。

感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...