Statically (cross) compiled vim for x86, x86-64 and mipsel
Published: 17-09-2014 | Author: Remy van Elst | Text only version of this article
❗ This post is over eight years old. It may no longer be up to date. Opinions may have changed.
Sometimes I need to manage a few systems with either low resources or a very restricted set of packages. On those systems no compilers or development libraries are available, however it is allowed to bring binaries.
A few of those systems are 32 bit x68 systems, some are MIPS systems, even worse. 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 those
ed. I have an ed cheatsheet for this purpose.
The solution for this problem is to create a statically (cross) compiled version
These instructions are for Debian/Ubuntu, tested on an Ubuntu 14.04 64 bit machine.
I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out!
Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.
You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $100 credit for 60 days.
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 install
apt-get install libc6-dev-i386
The MIPS hardware has a special toolchain which have specific instructions not covered here. The manufacturer probably covers this in their documentation.
Vim source code
Clone the vim source from github:
git clone https://github.com/b4winckler/vim.git
Go to the
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 <email@example.com>' --with-x=no --disable-gui --disable-netbeans --disable-pythoninterp --disable-python3interp --disable-rubyinterp --disable-luainterp
LDFLAGS make sure Vim gets statically compiled. The other options
disable any GUI support (x) and enable a portion of the features, namely the
small featureset. This lacks syntax highlighting and such. See below for a vim
If you need to compile on a 64 bit machine for a 32 bit machine, export the
To compile for
./configure --with-features=small --with-compiledby='Remy <firstname.lastname@example.org>' --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
$ 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 linux-gate.so.1 => (0xb77c7000) libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb7799000) libtinfo.so.5 => /lib/i386-linux-gnu/libtinfo.so.5 (0xb7779000) libselinux.so.1 => /lib/i386-linux-gnu/libselinux.so.1 (0xb7758000) libacl.so.1 => /lib/i386-linux-gnu/libacl.so.1 (0xb774e000) libgpm.so.2 => /usr/lib/i386-linux-gnu/libgpm.so.2 (0xb7748000) libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb75fa000) libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb75f6000) /lib/ld-linux.so.2 (0xb77c8000) libattr.so.1 => /lib/i386-linux-gnu/libattr.so.1 (0xb75ef000)
You can also use the
$ file vim vim: 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
vim, dynamically compiled (without the
LDFLAGS="-static"), is a
little bit smaller:
$ ls -la vim -rwxr-xr-x 1 remy remy 793K Sep 17 04:17 vim
That's it. You can copy/
vim file anywhere and use it, as long as it
is the correct architecture. Even on restricted systems in my case.
These instructions work for almost all programs you can compile. The
LDFLAGS="-static" is the magic part here. You can try it for yourself with
Here is the output of the
Tags: blog , compile , gcc , mips , ubuntu , vim
:version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Sep 17 2014 04:04:32) Included patches: 1-430 Compiled by Remy <email@example.com> 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=1 Linking: gcc -static -L/usr/local/lib -Wl,--as-needed -o vim -lm -ltinfo -ldl