Chinaunix首页 | 论坛 | 博客
  • 博客访问: 84521
  • 博文数量: 18
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 260
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-16 09:54
文章分类
文章存档

2008年(18)

我的朋友

分类:

2008-11-06 17:23:12

 
 
   

1、程序源文件:
如有三个文件:主文件:hello.cpp,类NUM的说明和实现文件:Num.h和Num.cpp,内容如下:


main.cpp:

#include "iostream"
#include "NUM.h"
using namespace std;
int main()
{
cout<<"Hello world"<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::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 vecArr;
};

2、相应的Makefile文件hello.mk:(注意TAB键)
all : main.exe
main.exe : main.obj NUM.obj
     link main.obj NUM.obj
main.obj : Num.h
     cl -c main.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

阅读(2938) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~