1、程序源文件:
如有三个文件:主文件:hello.cpp,类NUM的说明和实现文件:Num.h和Num.cpp,内容如下:
main.cpp:
#include "iostream"#include "NUM.h"using namespace std;int main(){cout<<"Hello world"<<endl;NUM a;a.Add(1);a.Add(3);a.Add(5);a.Display();return 0;}
NUM.cpp:
#include "iostream"#include "NUM.h"using namespace std;bool NUM::Add(int a){vecArr.push_back(a);return true;}void NUM::Display(){for(vector<int>::iterator it = vecArr.begin(); it != vecArr.end(); it ){cout<<*it<<'t';}return ;}
NUM.h
#include "vector"using namespace std;class NUM{public:bool Add(int a);void Display();private:vector<int> vecArr;};
2、相应的Makefile文件hello.mk:
- all :hello.exe
- hello.exe : hello.obj NUM.obj
- link hello.obj NUM.obj
- hello.obj : Num.h
- cl -c hello.cpp
- NUM.obj : NUM.h
- cl -c NUM.cpp
3、NMake的配置:
为NMake、cl、link运行设置环境变量:在目录《.net安装目录》Microsoft Visual Studio
.NET 2003Common7Tools中找到vsvars32.bat,在当前的dos窗口中运行它,以后在该窗口就能正常使用
NMake、cl、link了
编写makefile文件:按第二步编写makefile文件保存为hello.mk
运行NMake: NMake /f hello.mk
联系客服