简单编译c程序 simple to compile C program

####有时候,想简单编译些小程序,用openwrt的框架反而会不方便(主要是写那个Makefile不太方便)。其实方法很简单,我们需要找到openwrt下MT7688的编译器即可。

  1. 假设openwrt目录是在用户文件夹的根目录,则绝对目录大致是/home/mango/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin

  2. 修改用户目录的".bashrc"文件,在末尾位置添加一句:
    export PATH=$PATH:/home/mango/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin
    export STAGING_DIR=/home/mango/openwrt/staging_dir/

  3. 保存,使.bashrc有效:

source .bashrc
  1. 接下来终端里输入mipsel-openwrt-linux-gcc会出现:
mango@Ubuntu1404:~$ mipsel-openwrt-linux-gcc
mipsel-openwrt-linux-gcc: fatal error: no input files
compilation terminated.
mango@Ubuntu1404:~$ 
  1. 写一个经典的hello程序,并编译它
#include <stdio.h>
int main(void)
{
	printf("hello widora!");
}

mipsel-openwrt-linux-gcc main.c
会在本目录生成a.out

  1. 用scp方法拷贝到widora上,增加可执行权限,并执行
mango@Ubuntu1404:~$ scp a.out root@192.168.1.1:/root

在widora上找到文件并执行

root@Widora:~# chmod +x a.out
root@Widora:~# ./a.out
hello widora!

zymxjtu says:
1_1477497168624_Widora_User_Guide_1_Before_Getting_Started.pdf 0_1477497168624_Widora_用户指南_1_开始之前.pdf