I recently stumbled upon this very interesting vim plugin – OmniCppComplete. It promised to solve one of the problems that has been nagging me. While editing C/C++ code in vim, I have always wished if it could behave like Visual Studio and show structure/class members when we give object. or object->.
I wanted to try it out right away. But now comes the problem. It works only on vim 7 and above. It seems vim 7 onwards, OmniComplete feature is added which allows such stuff. At my workplace, the Debian server where I write code, has vim 6. Tough luck. Plus, I share the server with another 12 users, and do not have root powers. So next option is to build gvim from source. It wasn’t as easy, so this post explains the step I took to get it working.
Before we begin, a brief introduction about building stuff from source in Linux.
Step 0 – Brief introduction to building from source in Linux
Linux being open source, most software for Linux is open source too. That means you have full access to the source code. A bit of googling should get you what you are looking for. Traditionally, make is the utility used to build software for Unix like (and hence Linux) OSes. Linux has its own version of make called GNU make. It should be already installed on you Linux distro. Make depends upon a makefiles which describe what need to be done to build source code. To take care of the variations in Linux distros, GNU came up with Autoconf and Automake which can generate makefiles based upon your particular Linux distro. Typically there will be an executable file “configure” which tells Autoconf/Automake how to generate make files.
So the typical steps to build something from source in Linux is
tar -xzvf source.tgz # untar source code
tar -zjvf source.tar.bz2 # same as above, different compression algo
cd source # move to source code directory
./configure # Autoconf/Automake will generate makefiles
make # make will build the binaries
make install # make install will copy binaries to /usr/bin \
# or /usr/local/bin (may require root permissions)
Now if you have root permissions, you can follow the above steps. But there are times when you don’t have root permissions, or you do not want to install the binaries in the usual location, we can do this easily while invoking configure. Almost all configure scripts will take “–prefix” as an option. Here you can specify an alternate path where the binaries should be installed to when make install is given.
While compiling, I ran into some issues where configure picked my architecture to be 64 bit. But I wanted a 32 bit application. So I gave “–build” and “–host” options as i386-linux to specify a 32 bit compilation.
pkg-config is a neat utility that can help autoconf in finding the path of the required version of dependent packages. pkg-config will search the path in the same order specified by the environment variable PKG_CONFIG_PATH.
We are going to install gvim and the other stuff into /home/username/usr/bin since we do not have root permissions. So the typical commands that we are going to use are
export PREFIX=$HOME/usr export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig export HOST=1686-linux export BUILD=i686-linux ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD make make install
Also we will keep all source code in /home/username/usr/src. So
mkdir -p ~/usr/src cd ~/usr/src
Now we are all set. Let’s begin.
Step 1 – Get the source code of course 🙂
wget ftp://ftp.vim.org/pub/vim/unix/vim-7.2.tar.bz2
The latest version of gvim is 7.3 when I am writing this blog. But I got gvim setup a couple of weeks back, so still have 7.2. There is no separate code for gvim. The code for vim has the code for gvim as well. Gvim depends upon some graphical toolkit like GTK+ (GTK 1.2 from Gnome), GTK2 (current latest GTK from Gnome), Motif (from IBM’s CDE), Athena (from MIT) etc.
Step 2 – Untar it and try compiling
tar -xjvf vim-7.2.tar.bz2 cd vim72 ./configure --prefix $HOME/usr --host=i386-linux --build=i386-linux
Wait a minute. Configure could not find any graphical front ends, so skipping gvim. Bad :(. We want to get gvim 7.2 and vim 7.2 is not enough. Typical Linux distributions rarely contain the “devel” packages required for compiling dependent package. Vim could not find the header files of GTK+/GTK2/Motif/Athena (usually found in “devel” package) required to build gvim. Since we do not have root powers, we cannot just do apt-get install.
Step 3 – Get GTK+ and its dependencies’ source code
Well this is not as easy as it sounds. GTK has its own dependencies. I went through the compilation of each source package to list down all the dependencies. Here is the compiled list.
- glib2.24.0 Utility library required by almost everything in Gnome
- libxml2.7.1 XML parsing library required by Fontconfig
- libpng-1.4.3 PNG image manipulation library required by Pango
- atk-1.30.0 Accessibility Took Kit required by GTK
- freetype-2.4.2 Free fonts by Red Hat
- fontconfig-2.8.0 Configuring Fonts
- pixman-0.18.2 Pixel manipulation library required by Cairo
- cairo-1.8.10 Graphics library with PS/PDF like APIs required by Pango.
- pango-1.28.0 Font layout library required by GTK+
- gtk+-1.2.10 Graphics toolkit required by Gvim
wget http://ftp.gnome.org/pub/gnome/sources/glib/2.24/glib-2.24.0.tar.bz2 wget http://xmlsoft.org/sources/old/libxml2-2.7.1.tar.gz wget http://download.sourceforge.net/libpng/libpng-1.4.3.tar.gz wget http://ftp.gnome.org/pub/GNOME/sources/atk/1.30/atk-1.30.0.tar.bz2 wget http://sourceforge.net/projects/freetype/files/freetype2/2.4.2/freetype-2.4.2.tar.bz2/download wget http://fontconfig.org/release/fontconfig-2.8.0.tar.gz wget http://cairographics.org/releases/pixman-0.18.2.tar.gz wget http://cairographics.org/releases/cairo-1.8.10.tar.gz wget http://ftp.gnome.org/pub/gnome/sources/pango/1.28/pango-1.28.0.tar.gz wget http://ftp.gnome.org/pub/gnome/sources/gtk+/1.2/gtk+-1.2.10.tar.gz
Since I also use gvim for some coding in Python, I also got Python source code so that gvim was compiled with Python support (+python).
wget http://www.python.org/ftp/python/2.7/Python-2.7.tar.bz2
Step 4 – Untar all the stuff including GTK+ and Python
tar -xjvf glib-2.24.0.tar.bz2 tar -xzvf libxml2-2.7.1.tar.gz tar -xzvf libpng-1.4.3.tar.gz tar -xjvf atk-1.30.0.tar.bz2 tar -xjvf freetype-2.4.2.tar.bz2 tar -xzvf fontconfig-2.8.0.tar.gz tar -xzvf pixman-0.18.2.tar.gz tar -xzvf cairo-1.8.10.tar.gz tar -xzvf pango-1.28.0.tar.gz tar -xzvf gtk+-1.2.10.tar.gz tar -xjvf Python-2.7.tar.bz2
Notice that we used ‘j’ switch for tar.bz2 archives and ‘z’ switch for tar.gz archives.
Setp 5 – Build them
export PREFIX=$HOME/usr export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig export HOST=i686-linux export BUILD=1686-linux cd glib-2.24.0 ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD make make install cd ../libxml2-2.7.1 ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD make make install cd ../libpng-1.4.3/ ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD make make install cd ../atk-1.30.0/ ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD make make install cd ../freetype-2.4.2/ ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD make make install cd ../fontconfig-2.8.0/ ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD make make install cd ../pixman-0.18.2/ ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD make make install cd ../cairo-1.8.10/ ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD make make install cd ../pango-1.28.0/ ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD make make install cd ../gtk+-1.2.10/ ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD make make install cd ../Python-2.7 ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD make make install
All the dependencies are met. Now we are all set to build gvim. That leads us to
Step 6 – Build gvim
cd ../vim72 ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD \ --enable-mzschemeinterp --enable-pythoninterp --enable-tclinterp \ --enable-cscope --enable-fontset \ --with-compiledby=aufather make make install
Ta-da. Gvim is ready. Well almost. If you try to run gvim it will throw this error.
file $PREFIX/bin/gvim /home/aufather/usr/bin/gvim: symbolic link to `vim' /home/aufather/usr/bin/gvim --version /home/aufather/usr/bin/gvim: error while loading shared libraries: \ libgtk-1.2.so.0: cannot open shared object file: \ No such file or directory
Well this is because gvim could not find the shared libraries it requires to run. They are in $PREFIX/lib, but we have to tell that to bash. We do this by setting the LD_LIBRARY_PATH environment variable.
export LD_LIBRARY_PATH=$HOME/usr/lib ~/usr/bin/gvim --version VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Aug 16 2010 01:37:22) Compiled by aufather Normal version with GTK GUI. Features included (+) or not (-): -arabic +autocmd +balloon_eval +browse +builtin_terms +byte_offset +cindent +clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments +cryptv +cscope +cursorshape +dialog_con_gui +diff +digraphs +dnd -ebcdic -emacs_tags +eval +ex_extra +extra_search -farsi +file_in_path +find_in_path +float +folding -footer +fork() -gettext -hangul_input -iconv +insert_expand +jumplist -keymap -langmap +libcall +linebreak +lispindent +listcmds +localmap +menu +mksession +modify_fname +mouse +mouseshape -mouse_dec -mouse_gpm -mouse_jsbterm -mouse_netterm -mouse_sysmouse +mouse_xterm -multi_byte +multi_lang -mzscheme +netbeans_intg -osfiletype +path_extra -perl +postscript +printer -profile +python +quickfix +reltime -rightleft -ruby +scrollbind +signs +smartindent -sniff +statusline -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white +tcl +terminfo +termresponse +textobjects +title +toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo +vreplace +wildignore +wildmenu +windows +writebackup +X11 +xfontset +xim +xsmp_interact +xterm_clipboard -xterm_save
You can put these lines in your ~/.bashrc
export LD_LIBRARY_PATH=/home/username/usr/lib alias vim='/home/username/usr/bin/vim' alias gvim='/home/username/usr/bin/gvim'
That’s it. vim and gvim 7.2 is ready on your machine. Take it out for a spin 🙂
[…] found an article about how to compile gvim, but I do not have the packages for install in my ubuntu 10.10 repositories, I hope to find some […]
[…] found an article about how to compile gvim, but I don’t have the packages for install in my ubuntu 10.10 repositories, I hope to find […]
Very helpful, would have taken me ages to get it all built and running otherwise. However, there is a minor bug which causes Python to fail to build with
error “This platform’s pyconfig.h needs to define PY_FORMAT_LONG_LONG”
The issue is that you’ve defined:
export HOST=i686-linux
export BUILD=1686-linux
which ends up making Python think it should cross-compile. The BUILD should be i686-linux.
This topic is exactly what I’m looking for – build gvim in GNU/Linux without root permission. I followed instruction carefully. However at step 5, I ran configure command at glib-2.24.0 directory. I got teh error is as below:
Please advise.
Thanks,
Andrew
====================================================
==>./configure –prefix=$PREFIX –host=$HOST –build=$BUILD
checking for a BSD-compatible install… /usr/bin/install -c
checking whether build environment is sane… yes
checking for a thread-safe mkdir -p… /bin/mkdir -p
checking for gawk… gawk
checking whether make sets $(MAKE)… yes
checking whether to enable maintainer-specific portions of Makefiles… no
checking build system type… i686-pc-linux-gnu
checking host system type… i686-pc-linux-gnu
checking for the BeOS… no
checking for Win32… no
checking for Mac OS X Carbon support… checking for style of include used by make… GNU
checking for i686-linux-gcc… cc
checking whether the C compiler works… no
configure: error: in `/home/aho/vim/vim72/glib-2.24.0′:
configure: error: C compiler cannot create executables
See `config.log’ for more details.
========================================================
[…] found an article about how to compile gvim, but I don’t have the packages for install in my ubuntu 10.10 repositories, I hope to find […]
[…] found an article about how to compile gvim, but I don’t have the packages for install in my ubuntu 10.10 repositories, I hope to find […]