Skip to main content Logo (IEC resistor symbol)logo

Quis custodiet ipsos custodes?
Home | About | All pages | RSS Feed | Gopher

Statically (cross) compiled vim for x86, x86-64 and mipsel

Published: 17-09-2014 | Author: Remy van Elst | Text only version of this article

Table of Contents

Sometimes I need to manage a few systems with either low resources or a veryrestricted set of packages. On those systems no compilers or developmentlibraries are available, however it is allowed to bring binaries.

A few of those systems are 32 bit x68 systems, some are MIPS systems, evenworse. They serve a secure purpose, I cannot go in to much detail about them,except for they require a high level of security, they process certificates.

I really like vim as my editor, the only editor available by default on thosesystems is ed. I have an ed cheatsheet for this purpose.

The solution for this problem is to create a statically (cross) compiled versionof vim.

These instructions are for Debian/Ubuntu, tested on an Ubuntu 14.04 64 bitmachine.

If you like this article, consider sponsoring me by trying out a Digital OceanVPS. With this link you'll get $100 credit for 60 days). (referral link)

Install required packages

First install the required development libraries and git:

apt-get install libncurses5-dev git build-essential

If you need to cross compile from 64 bit to 32 bit, also installlibc6-dev-i386:

apt-get install libc6-dev-i386

The MIPS hardware has a special toolchain which have specific instructions notcovered here. The manufacturer probably covers this in their documentation.

Vim source code

Clone the vim source from github:

git clone

Go to the vim/src folder:

cd vim/src/

Compile time

Set the compile flags for vim and start the compile:

export LDFLAGS="-static"export MAKEFLAGS="-j4"export CFLAGS=""./configure --with-features=small  --with-compiledby='Remy <>'  --with-x=no  --disable-gui  --disable-netbeans  --disable-pythoninterp  --disable-python3interp  --disable-rubyinterp  --disable-luainterp 

The above LDFLAGS make sure Vim gets statically compiled. The other optionsdisable any GUI support (x) and enable a portion of the features, namely thesmall featureset. This lacks syntax highlighting and such. See below for a vim:version output.

If you need to compile on a 64 bit machine for a 32 bit machine, export thefollowing CFLAGS:

export CFLAGS="-m32"

To compile for mips:

./configure --with-features=small  --with-compiledby='Remy <>'  --with-x=no  --disable-gui  --disable-netbeans  --disable-pythoninterp  --disable-python3interp  --disable-rubyinterp  --disable-luainterp --target=mipsel-safenet # or mipsel-linux

Start the actual compile:



When it is finished you should have a fairly small vim file:

$ ls -la vim-rwxr-xr-x 1 remy remy 1.4M Sep 17 04:06 vim

Check that it is statically linked:

$ ldd vim    not a dynamic executable

A non-statically compiled vim gives me this:

$ ldd /usr/bin/vim =>  (0xb77c7000) => /lib/i386-linux-gnu/ (0xb7799000) => /lib/i386-linux-gnu/ (0xb7779000) => /lib/i386-linux-gnu/ (0xb7758000) => /lib/i386-linux-gnu/ (0xb774e000) => /usr/lib/i386-linux-gnu/ (0xb7748000) => /lib/i386-linux-gnu/ (0xb75fa000) => /lib/i386-linux-gnu/ (0xb75f6000)        /lib/ (0xb77c8000) => /lib/i386-linux-gnu/ (0xb75ef000)

You can also use the file command:

$ file vimvim: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, for GNU/Linux 2.6.26, BuildID[sha1]=0x97cb04dde25cd539487369524b0787fd422044be, not stripped

You can decease the filesize with 0.1 MB by stripping:

$ strip vim$ ls -la vim-rwxr-xr-x 1 remy remy 1.3M Sep 17 04:04 vim

The same vim, dynamically compiled (without the LDFLAGS="-static"), is alittle bit smaller:

$ ls -la vim-rwxr-xr-x 1 remy remy 793K Sep 17 04:17 vim

That's it. You can copy/scp the vim file anywhere and use it, as long as itis the correct architecture. Even on restricted systems in my case.

These instructions work for almost all programs you can compile. TheLDFLAGS="-static" is the magic part here. You can try it for yourself withother software.

Version info

Here is the output of the :version in vim itself:

:versionVIM - Vi IMproved 7.4 (2013 Aug 10, compiled Sep 17 2014 04:04:32)Included patches: 1-430Compiled by Remy <>Small version without GUI.  Features included (+) or not (-):+acl             -conceal         -farsi           -libcall         -mouse_sgr       -python3         -tag_old_static  -vreplace-arabic          -cryptv          -file_in_path    -linebreak       -mouse_sysmouse  -quickfix        -tag_any_white   +wildignore-autocmd         -cscope          -find_in_path    -lispindent      -mouse_urxvt     -reltime         -tcl             -wildmenu-balloon_eval    -cursorbind      -float           -listcmds        -mouse_xterm     -rightleft       +terminfo        +windows-browse          -cursorshape     -folding         -localmap        -multi_byte      -ruby            -termresponse    +writebackup+builtin_terms   -dialog          -footer          -lua             -multi_lang      -scrollbind      -textobjects     -X11-byte_offset     -diff            +fork()          -menu            -mzscheme        -signs           -title           -xfontset-cindent         -digraphs        -gettext         -mksession       -netbeans_intg   -smartindent     -toolbar         -xim-clientserver    -dnd             -hangul_input    -modify_fname    -path_extra      -sniff           -user_commands   -xsmp-clipboard       -ebcdic          -iconv           -mouse           -perl            -startuptime     -vertsplit       -xterm_clipboard-cmdline_compl   -emacs_tags      -insert_expand   -mouse_dec       -persistent_undo -statusline      -virtualedit     -xterm_save+cmdline_hist    -eval            +jumplist        -mouse_gpm       -printer         -sun_workshop    +visual          -xpm-cmdline_info    -ex_extra        -keymap          -mouse_jsbterm   -profile         -syntax          -visualextra-comments        -extra_search    -langmap         -mouse_netterm   -python          -tag_binary      -viminfo   system vimrc file: "$VIM/vimrc"     user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc"      user exrc file: "$HOME/.exrc"  fall-back for $VIM: "/usr/local/share/vim"Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -fno-strength-reduce -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1Linking: gcc   -static -L/usr/local/lib -Wl,--as-needed -o vim        -lm -ltinfo  -ldl
Tags: blog, compile, gcc, mips, ubuntu, vim