- 論壇徽章:
- 0
|
與LZ的方法不同
我比較懶,不想自己去寫出錯函數(shù),直接用apue作者的error.c和apue.h頭文件
由于編譯的時候常常加上error.c, -Wall, -o選項之類的,手指很累...
于是我寫了一個小腳本,如下:
#!/bin/sh
#gg
#以下是修改的gg腳本,添加了一個函數(shù),indent每一個.c和.h的功能
#wraper the gcc
#set -x
#用indent所有的c文件和頭文件(因為我向ssh中拷代碼的時候縮進總是出問題,所以需要indent)
go2indent()
{
for tt in $*
do
char=`echo $tt|cut -d. -f2`
if [ $char = "c" -o $char = "h" ]; then
char=""
#此處indent格式自己修改。
indent -ts2 -bli0 $tt
rm $tt~ >/dev/null 2>&1
fi
done
}
#不需要indent的話,直接注釋下面這條語句
go2indent $*
exec_obj=`echo $1|cut -d. -f1`
if gcc error.c $* -Wall -o $exec_obj; then
echo "gcc Done! Create executable file \"$exec_obj\"."
else
echo "gcc failed!"
exit 1
fi
#end
把error.c和apue.h拷到當前目錄
例,編譯test.c文件,輸入./gg test.c 就在當前目錄生成test可執(zhí)行文件
如果編譯多個文件,1111.c, 2222.c, 3333.c,輸入./gg 1111.c 2222.c 3333.c即可,生成的是1111可執(zhí)行文件.
需要動態(tài)連接庫libpthread.so?輸入./gg test.c -lpthread就行
[ 本帖最后由 科技牛 于 2007-8-27 19:52 編輯 ] |
|