首页 > 其他 > 详细

如何编写静态库

时间:2017-03-04 18:47:17      阅读:194      评论:0      收藏:0      [点我收藏+]

1.使用vs2013创建普通的应用台控制程序

2.在属性里选择静态库(.lib)

技术分享

编写库文件:

// mylib.h
#pragam once
int sum(int a,int b); 
//mylib.c
#include "mylib.h"
//函数实现
int sum(int a,int b)
{
   return (a+b);
}

3.编译,成功后会在目录下生成.lib文件

4.使用示例:

#include "mylib.h" // 使用库中的头文件
#include <stdio.h>
#pragam comment(lib,"mylib.lib") // 链接库文件
int main()
{
   int a = 1,b =2;
   printf("sum = %d \n",sum(a,b));
   return 0;
}

 或者不想每次都要链接库文件,就把环境配置好:

   01.打开属性

技术分享

  02.添加头文件目录、库文件目录等:

技术分享

技术分享

  Done!然后就不用这句了:

#pragam comment(lib,"mylib.lib"); // 手动链接库

  

如何编写静态库

原文:http://www.cnblogs.com/whlook/p/6502041.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!