開始時程式:
ngnsvr9 [** none **]/home/xionghailong/c++ $ cat orig.cpp
#include
using namespace std;
struct node
;node* addnode (node* p_list, int value)
void printlist(const node* p_list)
}int main()
printlist(p_list);
}當工程**很大時,**的可讀性會大大降低;我們可以將**分解為:linkedlist.cpp,linkedlist.h,orig.cpp
linkedlist.cpp:
ngnsvr9 [** none **]/home/xionghailong/c++/orig $ cat linkedlist.cpp
#include
#include "linkedlist.h"
using namespace std;
node* addnode (node* p_list, int value)
void printlist(const node* p_list)
}linkedlist.h:
ngnsvr9 [** none **]/home/xionghailong/c++/orig $ cat linkedlist.h
struct node
;node* addnode (node* p_list, int value);
void printlist(const node* p_list);
orig.cpp:
void printlist(const node* p_list);ngnsvr9 [** none **]/home/xionghailong/c++/orig $ cat orig.cpp
#include
#include "linkedlist.h"
using namespace std;
int main()
printlist(p_list);
}可以直接用如下命令進行執行:
ngnsvr9 [** none **]/home/xionghailong/c++/orig $ g++ orig.cpp linkedlist.cpp
in file included from orig.cpp:2:
linkedlist.h:8:36: warning: no newline at end of file
orig.cpp:17:2: warning: no newline at end of file
in file included from linkedlist.cpp:2:
linkedlist.h:8:36: warning: no newline at end of file
ngnsvr9 [** none **]/home/xionghailong/c++/orig $ ls
a.out linkedlist.cpp linkedlist.cpp.bak linkedlist.h linkedlist.h.bak makefile.txt makefile.txt.bak orig.cpp orig.cpp.bak
ngnsvr9 [** none **]/home/xionghailong/c++/orig $ ./a.out
enter value for list node: 2
enter value for list node: 2
enter value for list node: 2
enter value for list node: 2
enter value for list node: 23
enter value for list node: 3
enter value for list node: 3
enter value for list node: 3
enter value for list node: 3
enter value for list node: 333
33323
2222
採用makefile檔案可以更加直接明了:
makefile檔案如下:
ngnsvr9 [** none **]/home/xionghailong/c++/orig $ cat makefile.txt
all: orig
orig: orig.o linkedlist.o
g++ orig.o linkedlist.o -o orig
orig.o: orig.cpp
g++ -c orig.cpp
linkedlist.o: linkedlist.cpp
g++ -c linkedlist.cpp
clean:
rm -rf *o orig
執行:ngnsvr9 [** none **]/home/xionghailong/c++/orig $ make -f makefile.txt
g++ -c orig.cpp
in file included from orig.cpp:2:
linkedlist.h:8:36: warning: no newline at end of file
orig.cpp:17:2: warning: no newline at end of file
g++ -c linkedlist.cpp
in file included from linkedlist.cpp:2:
linkedlist.h:8:36: warning: no newline at end of file
g++ orig.o linkedlist.o -o orig
ngnsvr9 [** none **]/home/xionghailong/c++/orig $ ls
a.out linkedlist.cpp linkedlist.cpp.bak linkedlist.h linkedlist.h.bak linkedlist.o makefile.txt makefile.txt.bakorigorig.cpp orig.cpp.bak orig.o
ngnsvr9 [** none **]/home/xionghailong/c++/orig $ ./orig
enter value for list node: 2
enter value for list node: 2
enter value for list node: 1
enter value for list node: 2
enter value for list node: 3
enter value for list node: 1
enter value for list node: 23
enter value for list node: 4
enter value for list node: 5
enter value for list node: 56565
42313
2122
生成了可執行檔案orig
執行clean刪除.o 和可執行檔案
ngnsvr9 [** none **]/home/xionghailong/c++/orig $ make -f makefile.txt clean
rm -rf *o orig
ngnsvr9 [** none **]/home/xionghailong/c++/orig $ ls
a.out linkedlist.cpp linkedlist.cpp.bak linkedlist.h linkedlist.h.bak makefile.txt makefile.txt.bak orig.cpp orig.cpp.bak
希望對大家能有所幫助。
source檔案和makefile檔案編寫
一.makefile 沒有副檔名,它名字就叫makefile 內容如下 include ntmakeenv makefile.def wdm程式使用的所有makefile都這樣寫,我們只需寫乙個,編譯時把它拷貝到工作目錄下就行了 二.sources檔案就需要我們根據不同的場合修改了,不過基本模板如下...
ant呼叫make實現Makefile編譯
為了讓ant能執行make,還得用指令碼實現 linux sh指令碼實現,build.sh bin sh export build folder cd dirname 0 pwd prj 判斷makefile是否存在,如果不存在,則呼叫newprj.sh生成makefile if r build f...
lu,qr,svd分解以及matlab實現
將原正方 square 矩陣分解成乙個上三角形矩陣或是排列 permuted 的上三角形矩陣和乙個 下三角形矩陣,這樣的分解法又稱為lu分解法。它的用途主要在簡化乙個大矩陣的行列式值的計算過程,求逆矩陣,和求解聯立方程組。不過要注意這種分解法所得到的上下三角形矩陣並非唯一,還可找到數個不同 的一對上...