This is a text-only version of the following page on https://raymii.org: --- Title : Statically (cross) compiled vim for x86, x86-64 and mipsel Author : Remy van Elst Date : 17-09-2014 URL : https://raymii.org/s/blog/Statically_cross_compiled_vim_for_x86_x86-64_and_mips.html Format : Markdown/HTML --- 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 systems is `ed`. I have an [ed cheatsheet][1] for this purpose. The solution for this problem is to create a statically (cross) compiled version of `vim`. These instructions are for Debian/Ubuntu, tested on an Ubuntu 14.04 64 bit machine.

Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:

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 `libc6-dev-i386`: 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][3]: git clone https://github.com/b4winckler/vim.git 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 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 `:version` output. If you need to compile on a 64 bit machine for a 32 bit machine, export the following `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: make ### Results 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 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` command: $ 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 The same `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/`scp` the `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 other software. ### Version info Here is the output of the `:version` in `vim` itself: :version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Sep 17 2014 04:04:32) Included patches: 1-430 Compiled 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=1 Linking: gcc -static -L/usr/local/lib -Wl,--as-needed -o vim -lm -ltinfo -ldl [1]: https://raymii.org/s/tutorials/ed_cheatsheet.html [2]: https://www.digitalocean.com/?refcode=7435ae6b8212 [3]: https://github.com/b4winckler/vim --- License: All the text on this website is free as in freedom unless stated otherwise. This means you can use it in any way you want, you can copy it, change it the way you like and republish it, as long as you release the (modified) content under the same license to give others the same freedoms you've got and place my name and a link to this site with the article as source. This site uses Google Analytics for statistics and Google Adwords for advertisements. You are tracked and Google knows everything about you. Use an adblocker like ublock-origin if you don't want it. All the code on this website is licensed under the GNU GPL v3 license unless already licensed under a license which does not allows this form of licensing or if another license is stated on that page / in that software: This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Just to be clear, the information on this website is for meant for educational purposes and you use it at your own risk. I do not take responsibility if you screw something up. Use common sense, do not 'rm -rf /' as root for example. If you have any questions then do not hesitate to contact me. See https://raymii.org/s/static/About.html for details.