我想一切都在标题里了^^ 事实上,我正在使用 libtooling 开发一个工具,但我想抑制每个错误(该工具的目的是仅在正确的源上使用,因此错误输出会污染 stderr...)。
标题是libclang/libtooling,所以这里是libclang的答案。像这样创建你的
CXIndex
:
bool excludeDeclarationsFromPCH = false;
bool displayDiagnostics = false;
CXIndex index = clang_createIndex((int)excludeDeclarationsFromPCH, (int)displayDiagnostics);
请参阅文档。
您想重定向您的
std::cerr
输出吗?或者每个子进程的stderr
?如果是后一种情况,你可以这样做:
#include <unistd.h>
int fd = dup(2);
int n = open("/dev/null", O_WRONLY);
dup2(n, 2);
close(n);
//... do your thing ...
dup2(fd, 2); // put the stderr back where it belongs :D
close(fd);
CompilerInstance comp_inst;
comp_inst.createDiagnostics();
comp_inst.getDiagnostics().setSuppressAllDiagnostics( 1 );