gcc常见问题

显示系统所有预处理定义

显示 gcc 所有 define:

[root@localhost ~]# gcc -dM -E - < /dev/null

类似 g++ 还可以指定选项:

[root@localhost ~]# g++ -dM -E -x c++ /dev/null
[root@localhost ~]# g++ -dM -E -x c++ -std=c++11 /dev/null

显示支持的处理器和指令集

显示当前 gcc 支持的处理器:

[root@localhost ~]# gcc --version
gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)
[root@localhost ~]# gcc -c -Q -march=native --help=target | grep march
  -march=                               silvermont

使用自定义头文件路径

如果要忽略系统头文件路径,完全使用自定义头文件路径,可以:

~# gcc -nostdinc -I/custom/include/path/goes/here

强制忽略函数返回值

如果某些函数指定了 __attribute__ ((warn_unused_result)) 属性,那么调用者必须使用或检查函数的返回值,否则编译器会报错:

ignoring return value of ‘strscpy’, declared with attribute warn_unused_result [-Werror=unused-result]

如果不想单独使用或检查返回值,可以增加 (void)! 前缀:

(void)!strscpy(dest, src, count);