WRTnode-make V=s出错解决办法
WRTnode是基于Wi-Fi AP-Soc的开源硬件开发板。官方网址 http://wiki.wrtnode.com/index.php?title=Main_Page/zh-cn
对于初始学习WRTnode,尤其是之前没有学过Linux开发的人来说,总会遇到各种各样的问题,即使你是照着官方文档按流程做的。这不,按照官网的流程做个 helloworld,都遇到了困难。下面介绍一下我遇到的问题以及解决方法:
1.以下过程参考WRTnode官方教程:http://wiki.wrtnode.com/index.php?title=Openwrt_development/zh-cn
2.首先配置WRTnode的交叉编译环境OpenWrt,可以参考我的博客 http://blog.****.net/zhyulo/article/details/78732348
3.在package目录下创建helloworld目录,并进入helloworld目录:
$cd ~/OpenWrt/package
$mkdir helloworld $cd helloworld
4.在helloworld目录下,创建新目录 src,并进入到src目录。在src目录下创建hellowrold.c以及编译helloworld.c所需要的Makefile文件
$mkdir src $cd src $touch helloworld.c $touch Makefile
5.分别编辑helloworld.c和Makefile
注意:在命令行编辑文档时,编辑前先按下 'i';保存并退出时按下 Esc 按键,输入":wq"(输入" "中的),按回车。
$vim helloworld.c
#include <stdio.h> #include <unistd.h> int main(void) { printf("a hellowrold ipk for openwrt !!! \n"); return 0;
}
$vim Makefile
#build a Makefile for helloworld.c helloworld: helloworld.o $(CC) $(LDFLAGS) helloworld.o -o helloworld helloworld.o: helloworld.c $(CC) $(CFLAGS) -c helloworld.c clean: rm *.o helloworld
6.编写Makefile,这个Makefile文件是给OpenWRT读的。是用来生成软件包的,在上一步中我们写的Makefile是为了编译helloworld.c的,两个Makefile不同,也不在同一层目录下。在上一步中我们是在src目录下,现在我们要编写的Makefile要在上层目录,既是helloworld目录下。
$cd ../ $touch Makefile
$vim Makefile
############################################### #OpenWrt Makefile for helloworld program ############################################## include $(TOPDIR)/rules.mk # Name and release number of this package PKG_NAME:=helloworld PKG_RELEASE:=1 # This specifies the directory where we're going to build the program. # The root build directory, $(BUILD_DIR), is by default the build_mipsel # directory in your OpenWrt SDK directory PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) include $(INCLUDE_DIR)/package.mk # Specify package information for this program. # The variables defined here should be self explanatory. # If you are running Kamikaze, delete the DESCRIPTION # variable below and uncomment the Kamikaze define # directive for the description below define Package/helloworld SECTION:=utils CATEGORY:=Utilities TITLE:=Helloworld -- prints a snarky message endef # Uncomment portion below for Kamikaze and delete DESCRIPTION variable above 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 # Specify what needs to be done to prepare for building the package. # In our case, we need to copy the source files to the build directory. # This is NOT the default. The default uses the PKG_SOURCE_URL and the # PKG_SOURCE which is not defined here to download the source from the web. # In order to just build a simple program that we have just written, it is # much easier to do it this way. define Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) ./src/* $(PKG_BUILD_DIR)/ endef # We do not need to define Build/Configure or Build/Compile directives # The defaults are appropriate for compiling a simple program such as this one # Specify where and how to install the program. Since we only have one file, # the helloworld executable, install it by copying it to the /bin directory on # the router. The $(1) variable represents the root directory on the router running # OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install # directory if it does not already exist. Likewise $(INSTALL_BIN) contains the # command to copy the binary file from its current location (in our case the build # directory) to the install directory. define Package/helloworld/install $(INSTALL_DIR) $(1)/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/ endef # This line executes the necessary commands to compile our program. # The above define directives specify all the information needed, but this # line calls BuildPackage which in turn actually uses this information to build a package. $(eval $(call BuildPackage,helloworld))
7.以上过程问题都不大,下面就是编译了。首先回到顶层目录,执行make进行编译。这下问题来了:
$ cd ../../ $make V=s
8.啊哈,好多"failed",好多"error"。看的人好想哭!我就是按步骤做的,怎么会出问题。不过问题出现了,就要解决问题。下面是出现该问题的原因:
Makefile是make命令所需要执行的文件,文件中所有的执行命令(也就是缩进的部分)之前都要加Tab,注意:这里只能是Tab,不能是空格。官网上的Makefile文件代码由于网页版制的问题,所有应该是Tab的地方,全部变成了4个空格。所以解决问题的方法也就出来了:把所有的执行命令前的空格该成Tab。再次执行下make:
$make V=s
9.还是有好多的"failed"和"error",但是上一个错误已经没有了,这说明上一个问题已经解决了。但是,又有了新的问题。我们再来想办法解决掉这个问题:
首先,查看一下最先出错的位置:/home/user/OpenWrt/staging_dir/host/bin/ccache_cc: 2: exec: ccache: not found。它说的是 ccache 这个程序没有发现,我们可以执行下这个命令再试试:
$ ccache
果然,ccache 这个程序不能执行了。
10.ccache 这个程序执行不了的解决方法:
$ sudo apt-get install ccache
11.好了,我们再执行一下 ccache 试试看:
$ ccache
好了,ccache 问题解决!
12.再次执行一次make,看看是否编译成功:
$ make V=s
helloworld 编译成功!可以在 bin/ramips/packages/base 中找到编译好的文件 helloworld_1_ramips_24kec.ipk
$ cd ~/OpenWrt/bin/ramips/packages/base $ ls