【问题标题】:Clang cindex can't find header in unsaved_filesClang cindex 在 unsaved_files 中找不到标头
【发布时间】:2020-02-20 01:01:58
【问题描述】:

我正在尝试在 Python 中使用 clang.cindex,但是当我尝试传入一个虚拟标头时,它不起作用:

import sys
from clang import cindex
tu = cindex.Index.create().parse('t.cc', args=[], unsaved_files=[
    ('t.h', ''),
    ('t.cc', '#include "t.h"'),
])
for diag in tu.diagnostics:
    sys.stderr.write(diag.format() + "\n")

我收到的错误是:

t.cc:1:10: fatal error: 't.h' file not found

发生了什么事?为什么能找到t.cc,却找不到t.h

【问题讨论】:

    标签: python clang


    【解决方案1】:

    原来这是由于缺少./ 前缀。显然路径没有被规范化。

    这很好用:

    import sys
    from clang import cindex
    tu = cindex.Index.create().parse('./t.cc', args=[], unsaved_files=[
        ('./t.h', ''),
        ('./t.cc', '#include "t.h"'),
    ])
    for diag in tu.diagnostics:
        sys.stderr.write(diag.format() + "\n")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-29
      • 2021-09-18
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      相关资源
      最近更新 更多