我试图在Arch x86_64中构建一个使用PAPI 5.4.3.0库的项目。
为了简单起见,我在这两个文件中复制了我不理解的内容:
A.cpp
#include "string.h"
#include "papi.h"
int main() {
} B.cpp
#include "papi.h"
#include "string.h"
int main() {
} 当编译它(到一个对象文件)时,我得到以下信息:
(1)$ g++ A.cpp -c -std=c++11
(2)$ g++ A.cpp -c -std=c++11 -pedantic
In file included from b.cpp:2:0:
/usr/include/papi.h:1021:27: error: declaration of ‘int ffsll(long long int)’ has a different exception specifier
int ffsll(long long lli); //required for --with-ffsll and used in extras.c/papi.c
^
In file included from A.cpp:1:0:
/usr/include/string.h:524:26: error: from previous declaration ‘int ffsll(long long int) throw ()’
__extension__ extern int ffsll (long long int __ll)
(3)$ g++ B.cpp -c -std=c++11 -pedantic为什么-pedantic标志会引发错误,而不是警告?(2)
为什么第三次运行不引发任何东西(仅仅通过切换包含)?
发布于 2016-03-22 20:25:41
-pedantic允许与C++标准完全兼容,并禁用gcc扩展。因此,在这种模式下报告的内容通常是错误的。
至于为什么更改的顺序包含更改的错误,我只能猜测。我最好的猜测是,string.h .h定义了某些宏,这些宏是在papi.h中签入的。查看它的源代码可能会有帮助。
https://stackoverflow.com/questions/36164163
复制相似问题