Unable to start libclang: the specified '' module '' was not found ''

Following Eli and the glehmann manual ;

(on Windows)

installed LLVM-3.8.0-win32 from here

libclang-py3 package installed (version 0.3)

added C:\Program Files (x86)\LLVM\bin\libclang.dll to Path environment variables

When I try to execute the code below (taken from the manuals I mentioned above)

 clang.cindex.Config.set_library_path('C:\Program Files (x86)\LLVM\bin\libclang.dll') 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) index = clang.cindex.Index.create() tu = index.parse(cppsource) print('Translation unit:', tu.spelling) find_typerefs(tu.cursor, 'Person') 

I get the following error:

 C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/Duca/Desktop/PyPlag/rough-scripts/c++_parser_with_libclang.py Traceback (most recent call last): File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\site-packages\clang\cindex.py", line 3623, in get_cindex_library library = cdll.LoadLibrary(self.get_filename()) File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\ctypes\__init__.py", line 425, in LoadLibrary return self._dlltype(name) File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\ctypes\__init__.py", line 347, in __init__ self._handle = _dlopen(self._name, mode) OSError: [WinError 126] The specified module could not be found During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/Duca/Desktop/PyPlag/rough-scripts/c++_parser_with_libclang.py", line 49, in <module> index = clang.cindex.Index.create() File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\site-packages\clang\cindex.py", line 2238, in create return Index(conf.lib.clang_createIndex(excludeDecls, 0)) File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\site-packages\clang\cindex.py", line 141, in __get__ value = self.wrapped(instance) File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\site-packages\clang\cindex.py", line 3592, in lib lib = self.get_cindex_library() File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\site-packages\clang\cindex.py", line 3628, in get_cindex_library raise LibclangError(msg) clang.cindex.LibclangError: [WinError 126] The specified module could not be found. To provide a path to libclang use Config.set_library_path() or Config.set_library_file(). Process finished with exit code 1 

Also tried

downloaded cfe-3.8.0.src.tar from here and copied the clang.cindex module inside my script directory

LLVM-3.8.0-win64 is installed and the Path environment variable is updated, as well as the clang.cindex.Config.set_library_path (after reading this question )

copied libclang.dll from the installation directory to the Python DLL directory

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

without success.

+3
python clang libclang
source share
1 answer

I'm afraid the main culprit of your code is the inverse . You need to change clang.cindex.Config.set_library_path('C:\Program Files (x86)\LLVM\bin\libclang.dll') to clang.cindex.Config.set_library_file('C:/Program Files (x86)/LLVM/bin/libclang.dll') .

Alternatively, and I believe this is the best programming practice, you can use os.sep to process both the Windows and Linux separator stack.

Also, there is another problem in your code; namely, you need to change ref_node = clang.cindex.Cursor_ref(node) to ref_node = node.get_definition() to avoid getting AttributeError , since Cursor_ref no longer an attribute of the clang.cindex module.

After fixing the above, working with the parameters of simple_demo_src.cpp Person , you should not get any errors and see this output:

 Translation unit: simple_demo_src.cpp Found Person [line=7, col=21] Found Person [line=13, col=5] Found Person [line=24, col=5] Found Person [line=24, col=21] Found Person [line=25, col=9] 

which is Eli on the page .

+5
source share

All Articles