Coverity Scan 无法构建 <stdlib.h>定义了 _GNU_SOURCE [英] Coverity Scan fails to build <stdlib.h> with _GNU_SOURCE defined

查看:13
本文介绍了Coverity Scan 无法构建 <stdlib.h>定义了 _GNU_SOURCE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当定义了 _GNU_SOURCE 时,Coverity Scan Build Tool 无法在 Ubuntu 18.04 上编译任何包含 的 C 文件:

The Coverity Scan Build Tool fails to compile any C file that includes <stdlib.h> on Ubuntu 18.04 when _GNU_SOURCE is defined:

$ cat > main.c
#include <stdlib.h>
int main() {
}
$ 
$ gcc -D_GNU_SOURCE=1 -o main main.c 
$ 
$ /opt/cov-analysis/bin/cov-build --dir cov-int gcc -D_GNU_SOURCE=1 -o main main.c 
Coverity Build Capture (64-bit) version 2017.07 on Linux 4.15.0-20-generic x86_64
...
[WARNING] Emitted 0 C/C++ compilation units (0%) successfully
...
$ 

相同的构建在 Ubuntu 16.04 或未定义 _GNU_SOURCE 时完美运行:

The same build works perfectly on Ubuntu 16.04 or without _GNU_SOURCE defined:

$ /volatile/local/cov-analysis/bin/cov-build --dir cov-int gcc -o main main.c 
Coverity Build Capture (64-bit) version 2017.07 on Linux 4.15.0-20-generic x86_64
...
Emitted 1 C/C++ compilation units (100%) successfully
...
$ 

如何使用 Coverity Scan 来构建带有 _GNU_SOURCE 在 Ubuntu 18.04 上定义的 C 源代码?

How to get Coverity Scan to build C sources with _GNU_SOURCEdefined on Ubuntu 18.04?

对于那些感兴趣的文件 cov-int/build-log.txt 可以在这里找到:
https://gist.github.com/DimitriPapadopoulos/0dcd9018eed269501d508eed269501d57d

For those interested file cov-int/build-log.txt can be found here:
https://gist.github.com/DimitriPapadopoulos/0dcd9018eed26401cc6095087d9cc1d5

推荐答案

Coverity 未能定义 GCC 将定义的类型,但无论如何它都声称是 GCC.这是一个解决方法:https://gist.github.com/vathpela/0cede6d6d6eb5b0ec0791c6afc4282c340#file-fix_coverity-h"file-fix_coverity-h

Coverity is failing to define the types GCC would define, but then it's claiming to be GCC anyway. Here's a workaround: https://gist.github.com/vathpela/0cede6d6eb5b0ec0791c6afc4282c340#file-fix_coverity-h

一定要做到:

#include "fix_coverity.h"

stdlib.h 被直接或间接包含之前.

before stdlib.h gets included, whether directly or indirectly.

这篇关于Coverity Scan 无法构建 &lt;stdlib.h&gt;定义了 _GNU_SOURCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆