2012年11月14日学习研究报告

今天在ubuntu下写一个hello的程序,并在openwr-sdk环境中进行编译:

1、编译一个helloworld的软件包
现在用户目录下创建一个helloworld的目录,在目录想创建helloworld.c和Makefile(这个学怎样写,已经下载教程了,一共73页)
命令:
mkdir helloworld
cd helloworld
touch helloworld.c
touch Makefile
使用gedit打开 helloworld.c进行编辑输入下面的内容:

#include<stdio.h>
#include<unistd.h>

int main(void)
{
  printf("Hellow!");

  return 0;
}

使用gedit打开Makefile进行编辑输入下面的内容:

helloworld:helloworld.o
  $(CC) $(LDFLAGS) helloworld.o -o helloworld

helloworld.o:helloworld.c
  $(CC) $(CFLAGS) -c helloworld.c

clean:
  rm *.o helloworld

写完这两个文件后在终端主收入命令切换到上面两个文件所在的目录用make命令进行编译
cd helloworld
make

编译成功 再执行编译生成可执行文件是否可用
./helloworld
输出: Hellow!

执行成功了 说明源文件没有问题了。


2、解压昨天编译open-wrt固件生成的sdk压缩包:
tar -xvf OpenWrt-SDK-brcm63xx-for-linux-i686-gcc-4.6-linaro_uClibc-0.9.33.2.tar.bz2
cd OpenWrt-SDK-brcm63xx-for-linux-i686-gcc-4.6-linaro_uClibc-0.9.33.2
cd package
mkdir helloworld
cd helloworld

创建src目录,将之前创建的helloworld.c和Makefile复制到src目录下
mkdir src
cp /home/administrator/helloworld/helloworld.c src
cd /home/administrator/helloworld/Makefile src

然后在helloworld目录下创建Makefile文件,这个Makefile文件与前面复制的的Makefile文件不在同一目录下。
helloworld下的Makefile文件是给openwrt读的
src目录下的Makefile文件是针对helloworld给编译读的。

使用gedit打开helloworld下的Makefile输入下的内容(makefile不太会写,下面的是修改别的模版的)

include $(TOPDIR)/rules.mk

PKG_NAME:=helloworld
PKG_RELEASE:=1

PKG_BUIL_DIR:=$(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/helloworld
SECTION:=utils
CATEGORY:=Utilities
TITLE:=helloworld--prints a snarky message
endef


define Package/helloworld/description
if you can't figure out what this program does,you're probably
brain-dead and need immediate medical attention
endef

define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Package/helloworld/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
endef

$(eval $(call BuildPackage,helloworld))

写完上面的Makefile文件后回到sdk根目录
执行make进行编译,
编译成功后生成软件包就会放到 sdk根目录下bin/brcm63xx/packages/


软件包在openwrt-sdk上编译完成后,就可以上传到路由器上面进行安装了。

转载于:https://www.cnblogs.com/DengYuWei/archive/2012/11/14/2770316.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值