博文

目前显示的是标签为“OpenWRT”的博文

Compiling the Nim program on the OpenWRT router across platforms on Linux

Nim   is a very fun language, let's see how to run a program written by Nim on a router. Ready to work Install the Nim compiler, if you use Debian GNU/Linux,  apt install nim you can A mipsel OpenWRT router Write a Nim program Come to Hello World: echo "hello world" Prepare OpenWRT's build toolchain aria2c 'http://archive.openwrt.org/chaos_calmer/15.05.1/ramips/mt7621/OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2' tar xvf OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2 Configure the PATH environment variable to let the Nim compiler find the build toolchain export PATH = /dev/shm/OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/: $PATH Start compiling! nim -d:release --opt = size -d:ssl --cpu:mipsel --os:linux --gcc.exe:mipsel-openwrt-linux-gcc --gcc.linke...

在Linux上跨平台编译OpenWRT路由器上的Nim程序

Nim  是个很好玩儿的语言,我们来看看怎么在路由器上运行Nim编写的程序 准备工作 安装好Nim编译器,如果你用Debian GNU/Linux, apt install nim 即可 一台mipsel的OpenWRT路由器 写个Nim程序 来个Hello World: echo "hello world" 准备OpenWRT的编译工具链 aria2c 'http://archive.openwrt.org/chaos_calmer/15.05.1/ramips/mt7621/OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2' tar xvf OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2 配置PATH环境变量,让Nim编译器找到编译工具链 export PATH = /dev/shm/OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/: $PATH 开始编译吧! nim -d:release --opt = size -d:ssl --cpu:mipsel --os:linux --gcc.exe:mipsel-openwrt-linux-gcc --gcc.linkerexe:mipsel-openwrt-linux-gcc c helloworld.nim 在我的机器上编译之后187KB,对比Golang编译出来的十几MB,真是轻量太多了, 如果还想再小,可以用 upx 神器压缩一下: upx -9 --best --lzma helloworld 这样就只要70KB了,对于只有几MB ROM的路由器,真是福音