vc 的静态连接库调用

来源:互联网 发布:js array 排序 编辑:程序博客网 时间:2024/06/06 13:18

(1)創建win32 Static Library;
(2)定義端口函數,基本和DLL一樣,不過不要在def中定義;
(3)將生成的lib和對應的.h放入API程序目錄中;
(4)在project-〉setting-〉link中添加lib;
(5)在程序中#include “*.h”
(6)引用接口函數

 

调用的时候包含头文件,再加上#pragma comment(lib,"xxx.lib")

 

#ifdef __cplusplus
extern "C"{
#endif

#ifdef __cplusplus
}
#endif

 

//文件:lib.h
#ifndef LIB_H
#define LIB_H
extern "C" int add(int x,int y);   //声明为C编译、连接方式的外部函数
#endif

//文件:lib.cpp
#include "lib.h"
int add(int x,int y)
{
return x + y;
}

 
原创粉丝点击