python使用libclang的环境搭建,找不到Libclang
PHP中文网
PHP中文网 2017-04-17 12:57:25
[Python讨论组]

我已经将C:\Program Files (x86)\LLVM\bin加入到环境变量里的path里了
在代码中也用

clang.cindex.Config.set_library_file('C:\Program Files 
(x86)\LLVM\bin\libclang.dll')

指明了libclang.dll的位置
测试用的test.py整个文件是

import sys
import clang.cindex

def find_typerefs(node, typename):
    """ Find all references to the type named 'typename'
    """
    if node.kind.is_reference():
        ref_node = clang.cindex.Cursor_ref(node)
        if ref_node.spelling == typename:
            print 'Found %s [line=%s, col=%s]' % (
                typename, node.location.line, node.location.column)
    # Recurse for children of this node
    for c in node.get_children():
        find_typerefs(c, typename)
clang.cindex.Config.set_library_file('C:\Program Files (x86)\LLVM\bin\libclang.dll')
index = clang.cindex.Index.create()
tu = index.parse(sys.argv[1])
print 'Translation unit:', tu.spelling
find_typerefs(tu.cursor, sys.argv[2])

但是运行是仍提示找不到libclang
错误信息为
Traceback (most recent call last):
File "C:\Users\willzhang\Desktop\test_clang\test.py", line 16, in
index = clang.cindex.Index.create()
File "C:\Users\willzhang\Desktop\test_clang\clang\cindex.py", line 2047, in create
return Index(conf.lib.clang_createIndex(excludeDecls, 0))
File "C:\Users\willzhang\Desktop\test_clang\clang\cindex.py", line 141, in get
value = self.wrapped(instance)
File "C:\Users\willzhang\Desktop\test_clang\clang\cindex.py", line 3357, in lib
lib = self.get_cindex_library()
File "C:\Users\willzhang\Desktop\test_clang\clang\cindex.py", line 3388, in get_cindex_library
raise LibclangError(msg)
LibclangError: [Error 126] . To provide a path to libclang use Config.set_library_path() or Config.set_library_file().
请问这是怎么回事^_^

PHP中文网
PHP中文网

认证0级讲师

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号