libclang/libtooling 处理或关闭所有错误输出

问题描述 投票:0回答:3

我想一切都在标题里了^^ 事实上,我正在使用 libtooling 开发一个工具,但我想抑制每个错误(该工具的目的是仅在正确的源上使用,因此错误输出会污染 stderr...)。

c++ c libclang
3个回答
4
投票

标题是libclang/libtooling,所以这里是libclang的答案。像这样创建你的

CXIndex

bool excludeDeclarationsFromPCH = false;
bool displayDiagnostics = false;
CXIndex index = clang_createIndex((int)excludeDeclarationsFromPCH, (int)displayDiagnostics);

请参阅文档


0
投票

您想重定向您的

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);

0
投票
CompilerInstance comp_inst;
comp_inst.createDiagnostics();
comp_inst.getDiagnostics().setSuppressAllDiagnostics( 1 );
© www.soinside.com 2019 - 2024. All rights reserved.