
1.启动VS2008创建一个Win32控制台程序
2.选择静态库
3.创建两个文件lib.h和lib.cpp
//lib.h
#ifndef LIB_H
#define LIB_H
int add(int x,int y);
void print();
#endif
//lib.cpp
#include"lib.h"
#include "stdafx.h"
#include<iostream>
using namespace std; int add(int x,int y)
{
return x+y;
} void print()
{
cout << "LCLCLC\n";
}
4.点击“生成”中的”生成解决方案“
5.另创建一个工程Test1,将Test中的lib.h和Test.lib 放到Test1目录下
6.在Test1中创建一个cpp文件,代码如下
#include "lib.h"//函数原型声明
#pragma comment(lib,"Test.lib") //将静态库导入 #include<iostream>
using namespace std; int main()
{
cout <<add(,)<<endl;
print();
return ;
}
执行如下: