Solution to the "command-t.vim could not load the C extension." error.

Author
By Darío Rivera
Posted On in Vim

A few days ago we saw how to install command-t to search for files in Vim. For this, we saw that it was necessary to compile part of the plugin in the C language. However, I decided to separate the post and create one exclusively to deal with this error that is very common when you install this plugin. The complete error that you may encounter is similar to the following:

command-t.vim could not load the C extension.
Please see INSTALLATION and TROUBLE-SHOOTING in the help.
Vim Ruby version: 2.5.5-p157
Expected version: [unknown]-p[unknown]
For more information type:    :help command-t

As you can see, Vim has not correctly detected the version of Ruby [unknown]-p[unknown]. Your error may still be different and may not show the Expected version part.

Origin

This error is derived from the mismatch between the version of Ruby supported by Vim and the version with which the Vim plugin was compiled. To verify the version of Vim you should have installed, you must run the following command in Vim.

:ruby puts RUBY_VERSION

Once you have done this, you must make sure to install the necessary tools to compile the plugin on your operating system and install the appropriate version of Ruby according to the one supported by Vim (you can do this with RVM). You can review our article how to install command-t to search for files in Vim if you have Linux or MacOS to install these tools and the specific version of Ruby.

Environment preparation

Before starting the process of recompiling the plugin you must enter the folder where the CommandT plugin is located. To do this, you must enter the folder of Vim and look for the command-t ruby file.

cd ~/.vim
find . -name "extconf.rb"

You will get the path where it is located, something similar to the following

./plugged/command-t/ruby/command-t/ext/command-t/extconf.rb

You must enter the folder where this file is located.

cd ./plugged/command-t/ruby/command-t/ext/command-t

And finally, you must clean the environment of any other compilation we have done.

rm *.o && rm ext.bundle && rm metadata.rb && rm Makefile

Recompilation on MacOS

To compile on MacOS you must do it as follows:

/usr/local/opt/ruby/bin/ruby extconf.rb && make

You must avoid doing it with the ruby command directly as you will surely have different versions in your system provided by brew and rvm. You can check this by verifying these versions.

/usr/local/opt/ruby/bin/ruby --version
ruby --version

Recompilation on Linux

To compile on Linux you must do it as follows:

ruby extconf.rb && make

If everything went well, you will get an output like the following:

checking for float.h... yes
checking for ruby.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for fcntl.h... yes
checking for stdint.h... yes
checking for sys/errno.h... yes
checking for sys/socket.h... yes
checking for ruby/st.h... yes
checking for st.h... yes
checking for pthread_create() in -lpthread... yes
creating Makefile
compiling ext.c
compiling heap.c
compiling match.c
compiling matcher.c
compiling watchman.c
linking shared-object ext.so

After this, you can enter vim and use the plugin.


Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.