As of March 2021, YouCompleteMe compiles fine on Termux, but it crashes once the plugin is loaded. The following error can be noticed in the logs:
ImportError: dlopen failed: cannot locate symbol "_ZNSt6__ndk14__fs10filesystem18__weakly_canonicalERKNS1_4pathEPNS_10error_codeE" referenced by "/data/data/com.termux/files/home/.vim/bundle/YouCompleteMe/third_party/ycmd/ycm_core.so"...
The problem is caused by the lack of support for std::filesystem
on ndk prior to r22. While there is an ongoing PR that aims to upgrade Termux to use ndk r22, the instructions below can be used to run YouCompleteMe on Termux before the linked PR gets merged.
-
Install the prerequisite Termux packages.
pkg install vim-python git python clang cmake
-
Install Vundle by following the official instructions. This includes cloning the repository and editing your
vimrc
as necessary. -
Install
YouCompleteMe
by adding it to the list of plugins in yourvimrc
file, and then running the:PluginInstall
command in vim.Plugin 'ycm-core/YouCompleteMe'
:PluginInstall
-
Apply the provided patch1 to use
ghc::filesystem
instead ofstd::filesystem
inycmd
.cd ~/.vim/bundle/YouCompleteMe/third_party/ycmd curl https://gist.githubusercontent.com/micjabbour/ef6181f9a2cf17f90a5744fcf909438a/raw/ycmd_filesystem_patch.patch | git apply --3way -
-
Build and install YouCompleteMe2, and configure it to use the
clangd
completer.3python install.py --clangd-completer
-
Configure
YouCompleteMe
to useclangd
from thelibllvm
Termux package.4 This can be done by adding the following line to the end of yourvimrc
file.let g:ycm_clangd_binary_path="/data/data/com.termux/files/usr/bin/clangd"
If you are new to YouCompleteMe
, it might be a bit tricky to configure it properly for your project. In this case, you can start by testing your installation on the example projects used for ycmd
tests.
vim ~/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/tests/clangd/testdata/basic.cpp
vim ~/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/tests/python/testdata/basic.py
-
^ The patch has been written for commit
dbf67638
in theYouCompleteMe
repository (the master branch at the time of this writing). If you are from the future, and the patch no longer applies, you might have to manually resolve the merge conflict. The patch simply modifiesCMakeLists.txt
to downloadghc::filesystem
header to the build directory, replaces all#include <filesystem>
with#include <ghc_filesystem.hpp>
, and changes all references tostd::filesystem
to useghc::filesystem
instead. -
^ If you are on a device with limited RAM, try using
export YCM_CORES=1
before runninginstall.py
. This controls the number of compilation jobs executed in parallel (a.k.a.-j
), and overrides the defaultmultiprocessing.cpu_count()
. -
^ In my experiments, using
--clang-completer
(with--system-libclang
) caused frequent crashes in ycmd. I couldn't identify the problem by looking at the logs, but I had a much better experience when using the--clangd-completer
. -
^ Neither
libclang
norclangd
binaries available inycm_core
's bintray (which are downloaded automatically when runninginstall.py
) are usable on android, because they use non-compatible ABIs.
(newenv) ~/.../bundle/YouCompleteMe $ python install.py --clangd-completer
1 error generated. make[3]: *** [ycm/CMakeFiles/ycm_core.dir/build.make:146: ycm/CMakeFiles/ycm_core.dir/IdentifierUtils.cpp.o] Error 1 make[2]: *** [CMakeFiles/Makefile2:2675: ycm/CMakeFiles/ycm_core.dir/all] Error 2 make[1]: *** [CMakeFiles/Makefile2:2682: ycm/CMakeFiles/ycm_core.dir/rule] Error 2 make: *** [Makefile:962: ycm_core] Error 2 FAILED ERROR: the build failed.