链接 PAPI 时迂腐引发错误

Pedantic raising error when linking PAPI

我正在尝试在 Arch Linux 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)

为什么第 3 个 运行 什么都不引发(只是通过切换包含)?

-pedantic 启用与 C++ 标准的完全兼容并禁用 gcc 扩展。所以在这种模式下报告的东西通常是错误的。

至于为什么改变include的顺序会改变错误,我只能猜测。我最好的猜测是 string.h 定义了某些在 papi.h 中检查的宏。查看它的源代码可能会有所帮助。