Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wont find libclang automatically on Debian Testing #770

Open
nolange opened this issue Dec 10, 2022 · 10 comments
Open

Wont find libclang automatically on Debian Testing #770

nolange opened this issue Dec 10, 2022 · 10 comments
Labels

Comments

@nolange
Copy link

nolange commented Dec 10, 2022

System info:

  • Sublime Text version: 14 Build 4143
  • Which system are you on: `Debian Linux Testing/Bookworm x86_64
  • Clang version: 15.0.6

What happens:

The plugin is unable to find the libclang library, unless I provide the full path with

  "libclang_path": "/usr/lib/x86_64-linux-gnu/libclang-$clang_version.so.1"

The library is available under the following paths:

/usr/lib/x86_64-linux-gnu/libclang-15.so.1
/usr/lib/x86_64-linux-gnu/libclang-15.so.15
/usr/lib/x86_64-linux-gnu/libclang-15.so.15.0.6

Output from clang --version

Debian clang version 15.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

PS. I commented out the line in the settings shipped with the plugin,
doesnt make a difference for me, but it seems odd to have this as default:

  "libclang_path": "<some_path_here>", 
Log that illustrates the issue:
startup, version: 4143 linux x64 channel: stable
executable: /opt/sublime_text/sublime_text
application: /opt/sublime_text
working dir: /home/noppl
packages path: /home/noppl/.config/sublime-text/Packages
state path: /home/noppl/.config/sublime-text/Local
zip path: /opt/sublime_text/Packages
zip path: /home/noppl/.config/sublime-text/Installed Packages
ignored_packages: ["Vintage"]
pre session restore time: 0.391272
loading dictionary Packages/Language - English/en_US.dic
startup time: 0.581365
git: located Sublime Merge installed at /opt/sublime_merge
git: using configuration from system git install
git: tracking working dir /home/noppl/git/buildroot-external
first paint time: 0.621976
reloading python 3.3 plugin 0_package_control_loader.00-package_control
reloading python 3.3 plugin 0_package_control_loader.01-pygments
reloading python 3.3 plugin 0_package_control_loader.50-markupsafe
reloading python 3.3 plugin 0_package_control_loader.50-pymdownx
reloading python 3.3 plugin 0_package_control_loader.50-python-markdown
reloading python 3.3 plugin 0_package_control_loader.50-pyyaml
reloading python 3.3 plugin 0_package_control_loader.51-python-jinja2
reloading python 3.3 plugin 0_package_control_loader.55-mdpopups
reloading python 3.3 plugin Clang Format.clang_format
reloading python 3.3 plugin Indent XML.indentxml
reloading python 3.3 plugin Indent XML.setup
reloading python 3.3 plugin Package Control.1_reloader
reloading python 3.3 plugin Package Control.2_bootstrap
reloading plugin Default.arithmetic
reloading plugin Default.auto_indent_tag
reloading plugin Default.block
reloading plugin Default.colors
reloading plugin Default.comment
reloading plugin Default.convert_color_scheme
reloading plugin Default.convert_syntax
reloading plugin Default.copy_path
reloading plugin Default.echo
reloading plugin Default.exec
reloading plugin Default.fold
reloading plugin Default.font
reloading plugin Default.goto_line
reloading plugin Default.history_list
reloading plugin Default.html_print
reloading plugin Default.indentation
reloading plugin Default.install_package_control
reloading plugin Default.keymap
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_context_url
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.profile
reloading plugin Default.quick_panel
reloading plugin Default.rename
reloading plugin Default.run_syntax_tests
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.settings
reloading plugin Default.show_scope_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.ui
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin ShellScript.ShellScript
reloading python 3.3 plugin Package Control.Package Control
reloading python 3.3 plugin EasyClangComplete.EasyClangComplete
reloading python 3.3 plugin VimModelines.vimmodelines
plugins loaded
[ECC:DEBUG]:[settings_storage.py]:[need_reparse]:[MainThread]: settings complete
[ECC:DEBUG]:[settings_manager.py]:[settings_for_view]:[MainThread]: no settings for view 29. Reinitializing.
[ECC:DEBUG]:[settings_storage.py]:[__load_vars_from_settings]:[MainThread]: Overriding settings by project ones if needed:
[ECC:DEBUG]:[settings_storage.py]:[__load_vars_from_settings]:[MainThread]: Valid prefixes: ['ecc_', 'easy_clang_complete_']
[ECC:DEBUG]:[settings_storage.py]:[__load_vars_from_settings]:[MainThread]: Reading settings...
[ECC:DEBUG]:[settings_storage.py]:[__load_vars_from_settings]:[MainThread]: Settings sucessfully read...
[ECC:INFO]:[clang_utils.py]:[get_clang_version_str]:[MainThread]: Getting version from command: `clang++ -v`
[ECC:DEBUG]:[settings_storage.py]:[__populate_common_flags]:[MainThread]: Populating common_flags with current variables.
[ECC:DEBUG]:[file.py]:[expand_all]:[MainThread]: Populated '$project_base_path/src' to '/src'
[ECC:DEBUG]:[file.py]:[expand_all]:[MainThread]: Populated '/usr/lib/clang/$clang_version/include' to '['/usr/lib/llvm-15/lib/clang/15.0.6/include']'
[ECC:DEBUG]:[file.py]:[expand_all]:[MainThread]: Populated '$file_path' to '['/tmp/ZBuild/build/busybox-1.35.0/loginutils']'
[ECC:DEBUG]:[file.py]:[expand_all]:[MainThread]: Populated '~/some_folder/*' to '['/home/noppl/some_folder/*']'
[ECC:DEBUG]:[file.py]:[expand_all]:[MainThread]: Populated '$project_base_path/some/project/path/*' to '['/some/project/path/*']'
Traceback (most recent call last):
  File "/opt/sublime_text/Lib/python33/sublime_plugin.py", line 528, in on_api_ready
    plc()
  File "/home/noppl/.config/sublime-text/Packages/EasyClangComplete/EasyClangComplete.py", line 88, in plugin_loaded
    handle_plugin_loaded_function()
  File "/home/noppl/.config/sublime-text/Packages/EasyClangComplete/EasyClangComplete.py", line 286, in on_plugin_loaded
    self.on_activated_async(sublime.active_window().active_view())
  File "/opt/sublime_text/Lib/python33/sublime_plugin.py", line 190, in exception_handler
    return event_handler(*args)
  File "/home/noppl/.config/sublime-text/Packages/EasyClangComplete/EasyClangComplete.py", line 336, in on_activated_async
    settings = EasyClangComplete.settings_manager.settings_for_view(view)
  File "/home/noppl/.config/sublime-text/Packages/EasyClangComplete/plugin/settings/settings_manager.py", line 56, in settings_for_view
    self.__init_for_view(view)
  File "/home/noppl/.config/sublime-text/Packages/EasyClangComplete/plugin/settings/settings_manager.py", line 104, in __init_for_view
    self.__settings_dict[view_id].update_from_view(view)
  File "/home/noppl/.config/sublime-text/Packages/EasyClangComplete/plugin/settings/settings_storage.py", line 165, in update_from_view
    self.libclang_path)[0]
IndexError: list index out of range
Loaded VimModelines
[ECC:DEBUG]:[EasyClangComplete.py]:[on_activated_async]:[Dummy-4]: on_activated_async view id 29
[ECC:DEBUG]:[view_config_manager.py]:[load_for_view]:[Thread-5]: Generate new config for path: 29
[ECC:INFO]:[view_config.py]:[__init_completer]:[Thread-5]: init completer based on libclang
[ECC:DEBUG]:[lib_complete.py]:[__init__]:[Thread-5]: using bundled cindex: EasyClangComplete.plugin.clang.cindex50
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Platform: Linux, ('64bit', '')
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Python version: 3.3.6
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: User provided libclang_path: ''
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Searching for: 'libclang-15..so'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Generating search folder
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Libclang search output = 'libclang-15..so'
[ECC:DEBUG]:[clang_utils.py]:[dir_from_output]:[Thread-5]: Real output: libclang-15..so
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Checking path: ./libclang-15..so
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Clang could not find './libclang-15..so'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Searching for: 'libclang.so'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Generating search folder
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Libclang search output = 'libclang.so'
[ECC:DEBUG]:[clang_utils.py]:[dir_from_output]:[Thread-5]: Real output: libclang.so
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Checking path: ./libclang.so
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Clang could not find './libclang.so'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Searching for: 'libclang-15..so.10'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Generating search folder
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Libclang search output = 'libclang-15..so.10'
[ECC:DEBUG]:[clang_utils.py]:[dir_from_output]:[Thread-5]: Real output: libclang-15..so.10
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Checking path: ./libclang-15..so.10
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Clang could not find './libclang-15..so.10'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Searching for: 'libclang.so.10'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Generating search folder
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Libclang search output = 'libclang.so.10'
[ECC:DEBUG]:[clang_utils.py]:[dir_from_output]:[Thread-5]: Real output: libclang.so.10
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Checking path: ./libclang.so.10
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Clang could not find './libclang.so.10'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Searching for: 'libclang-15..so.9'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Generating search folder
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Libclang search output = 'libclang-15..so.9'
[ECC:DEBUG]:[clang_utils.py]:[dir_from_output]:[Thread-5]: Real output: libclang-15..so.9
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Checking path: ./libclang-15..so.9
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Clang could not find './libclang-15..so.9'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Searching for: 'libclang.so.9'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Generating search folder
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Libclang search output = 'libclang.so.9'
[ECC:DEBUG]:[clang_utils.py]:[dir_from_output]:[Thread-5]: Real output: libclang.so.9
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Checking path: ./libclang.so.9
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Clang could not find './libclang.so.9'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Searching for: 'libclang-15..so.8'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Generating search folder
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Libclang search output = 'libclang-15..so.8'
[ECC:DEBUG]:[clang_utils.py]:[dir_from_output]:[Thread-5]: Real output: libclang-15..so.8
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Checking path: ./libclang-15..so.8
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Clang could not find './libclang-15..so.8'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Searching for: 'libclang.so.8'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Generating search folder
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Libclang search output = 'libclang.so.8'
[ECC:DEBUG]:[clang_utils.py]:[dir_from_output]:[Thread-5]: Real output: libclang.so.8
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Checking path: ./libclang.so.8
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Clang could not find './libclang.so.8'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Searching for: 'libclang-15..so.7'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Generating search folder
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Libclang search output = 'libclang-15..so.7'
[ECC:DEBUG]:[clang_utils.py]:[dir_from_output]:[Thread-5]: Real output: libclang-15..so.7
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Checking path: ./libclang-15..so.7
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Clang could not find './libclang-15..so.7'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Searching for: 'libclang.so.7'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Generating search folder
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Libclang search output = 'libclang.so.7'
[ECC:DEBUG]:[clang_utils.py]:[dir_from_output]:[Thread-5]: Real output: libclang.so.7
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Checking path: ./libclang.so.7
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Clang could not find './libclang.so.7'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Searching for: 'libclang-15..so.1'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Generating search folder
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Libclang search output = 'libclang-15..so.1'
[ECC:DEBUG]:[clang_utils.py]:[dir_from_output]:[Thread-5]: Real output: libclang-15..so.1
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Checking path: ./libclang-15..so.1
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Clang could not find './libclang-15..so.1'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Searching for: 'libclang.so.1'
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Generating search folder
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Libclang search output = 'libclang.so.1'
[ECC:DEBUG]:[clang_utils.py]:[dir_from_output]:[Thread-5]: Real output: libclang.so.1
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Checking path: ./libclang.so.1
[ECC:DEBUG]:[clang_utils.py]:[find_libclang]:[Thread-5]: Clang could not find './libclang.so.1'
[ECC:ERROR]:[clang_utils.py]:[find_libclang]:[Thread-5]: No libclang found!
[ECC:ERROR]:[lib_complete.py]:[__init__]:[Thread-5]: error: libclang.so: cannot open shared object file: No such file or directory. To provide a path to libclang use Config.set_library_path() or Config.set_library_file().
[ECC:ERROR]:[view_config.py]:[__init_completer]:[Thread-5]: cannot initialize completer with libclang.
[ECC:INFO]:[view_config.py]:[__init_completer]:[Thread-5]: falling back to using clang in a subprocess.
[ECC:INFO]:[view_config.py]:[__init_completer]:[Thread-5]: init completer based on clang from cmd
[ECC:DEBUG]:[file.py]:[get_temp_dir]:[Thread-5]: Folder /tmp/EasyClangComplete exists.
@niosus
Copy link
Owner

niosus commented Dec 11, 2022

This sound strange. Did you remove the libclang_path before you ran this? Does the error happen with it removed? Also, what do you mean you removed it from the settings shipped with the plugin? You mean you changed it directly in the repo? That might cause the problem you're seeing.

@nolange
Copy link
Author

nolange commented Dec 11, 2022

I did experience this on 2 systems without touching the configuration, I tried removing libclang_pathI tried setting it to a sane value. No difference for this issue.

If you look at the log, the plugin searches for 'libclang-15..so', 'libclang-15..so.1' and similar. Seems the bug is in the generated library names (additional .), not the path

@niosus
Copy link
Owner

niosus commented Dec 11, 2022

Hmm, you're right. That's very strange. It seems that for some reason the version of clang is not parsed correctly. What I don't understand is why it is not trimmed to two digits in here:

if current_system == "Linux":
# We only care about first two digits on Linux.
version_str = version_str[0:3]

So what I'm wondering now is what is the output of this command on your system:

clang -v

@nolange
Copy link
Author

nolange commented Dec 11, 2022

aint that the first 3 characters (including .): version_str[0:3]

# clang -v

Debian clang version 15.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64

@niosus
Copy link
Owner

niosus commented Dec 12, 2022

As far as I know the stopping index of a slice is non-inclusive. But you could have a look into the code and try to help me out by checking which version it reports 🤔

@nolange
Copy link
Author

nolange commented Dec 12, 2022

As far as I know the stopping index of a slice is non-inclusive.

Yes, and that means 3 characters {0, 1, 2}. Inclusive would be 4.
Its a weird way to split up a version string for sure.

But you could have a look into the code and try to help me out by checking which version it reports

Not sure what you mean with "it", the content of version_str?
Dont know how either, I would just copy out python code and run it seperately.

@nolange
Copy link
Author

nolange commented Dec 12, 2022

digged around a bit.

I guess the code you linked expects single-digit versions like 3.8.2 trying to extract 3.8.
I fixed it for versions >= 4 (changed the versioning to always increase major version),
this likely wont work for 3.x:

        if current_system == "Linux": 
            # We only care about first two digits on Linux.
            version_str = version_str.split(".")[0]

One one of my systems, even with the code above not working, the "second pass" does, and is quite likely the
reason no one reported a bug yet:

clang -print-file-name=libclang.so.1   
/usr/lib/llvm-15/bin/../lib/libclang.so.1

(Need to have a look at the broken systems later)

I believe clang -print-file-name=libclang.so.1should be the first attempt, should work on any non-ancient clang installation.

@niosus
Copy link
Owner

niosus commented Dec 15, 2022

Yep, you're totally right. I hope I will be able to fix this over the weekend. Thanks for reporting and digging!

@nolange
Copy link
Author

nolange commented Dec 19, 2022

Turns out clang will modify the searchpath to include /usr/lib/llvm-15/bin/../lib only if libc++.so is found there, that was the difference between my machines.
The one which did not have libc++-15-dev installed, could not locate clang -print-file-name=libclang.so.1.

Messy stuff, not sure what's the best way to solve this. I think taking the programs paths from clang -print-search-dirs, adding ../lib would be worth a try.

#  clang -print-search-dirs
programs: =/usr/bin:/usr/lib/llvm-15/bin:/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/bin
libraries: =/usr/lib/llvm-15/lib/clang/15.0.6:/usr/bin/../lib/gcc/x86_64-linux-gnu/12:/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../lib64:/lib/x86_64-linux-gnu:/lib/../lib64:/usr/lib/x86_64-linux-gnu:/usr/lib/../lib64:/usr/lib/llvm-15/bin/../lib:/lib:/usr/lib

@Letterus
Copy link

Letterus commented Apr 3, 2023

I'm able to confirm this issue on Debian Stable (Bullseye) using clang-14. Even using $clang_version seems to not work, I need to provide 14 to libclang_path manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants