方法主要有兩種:1) SDK編譯 2)源碼編譯
1.SDK編譯軟件安裝包IPK
從上邊的教程我們已經可以看到怎么去獲得SDK包了,然后怎么使用這個包,看教程:
http://my.oschina.net/hevakelcj/blog/410633
這個教程已經詳實地介紹了編譯的步驟,步驟是沒有問題的。但是!SDK編譯比較坑,就算你完全正確,他就是給你報錯,我就死在了下圖這個錯誤上:

意思是makefile 32行前邊少了個Tab,但是無論是怎么改,他就是報錯 = = 所有努力都是徒勞無意義的。
同樣的代碼同樣的makefile,在用源碼編譯的方法是完全可行的。
所以,強烈采用源碼編譯而不是SDK編譯。
2.源碼編譯軟件安裝包IPK
前邊的教程已經講到怎么編譯出ipk包了,其實就是那個步驟,下邊講講怎么寫自己package,下邊以helloworld為例:
先創建自己的包目錄,以及外層makefile:
mkdir helloworld
cd helloworld
mkdir src
vi makefile
然后在這個makefile里邊填寫如下內容,(內容可以參考官網的說明)
include $(TOPDIR)/rules.mk # Name and release number of this package PKG_NAME:=helloworld PKG_RELEASE:=1 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) include $(INCLUDE_DIR)/package.mk 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 It is Duval`s demo. endef define Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) ./src/* $(PKG_BUILD_DIR)/ endef #define Build/Compile # $(MAKE) -C $(PKG_BUILD_DIR) \ # $(TARGET_CONFIGURE_OPTS) CFLAGS="$(TARGET_CFLAGS) -I$(LINUX_DIR)/include" #endef define Package/helloworld/install $(INSTALL_DIR) $(1)/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/ endef $(eval $(call BuildPackage,helloworld))
然后 進入src,去編寫helloworld.C
cd src
vi helloworld.c
helloworld.c 里邊填寫
#include<stdio.h>
int main(void)
{
printf("yyyy\n");
return 0;
}
為helloworld.c編寫makefile
vi makefile
makefile 里邊填寫
# build helloworld executable when user executes "make" helloworld: helloworld.o $(CC) $(LDFLAGS) helloworld.o -o helloworld helloworld.o: helloworld.c $(CC) $(CFLAGS) -c helloworld.c # remove object files and executable when user executes "make clean" clean: rm *.o helloworld
然后把 這個helloworld的package包拷貝到源碼的./package目錄下邊。
然后運行
make defconfig
make menuconfig
然后在 menuconfig的菜單中找到helloworld,具體是菜單那里,就看你外層makefile怎么寫的。然后找到后在前邊勾選M ,表示僅編譯不固化到固件中。
然后運行編譯
make -j1 V=s
最后在bin目錄下可以找到自己要的ipk包。
