`
xkxjy
  • 浏览: 42937 次
  • 性别: Icon_minigender_1
  • 来自: 沈阳
社区版块
存档分类
最新评论

VS 静态库的编写

阅读更多

Visual Studio 下静态库的编写

使用VS建立 控制台--Static library(静态库) 项目

 

libTest.h 头文件

#ifndef GUARD_LIBTEST_H
#define GUARD_LIBTEST_H

#ifdef __cplusplus
extern "C" {
#endif

int myadd(int a, int b); 

#ifdef __cplusplus
}
#endif

#endif // end GUARD_LIBTEST_H

 

libTest.cpp源文件

#include "libTest.h"

int myadd(int a, int b)
{
    return a + b;
}

 

使用起来就是加入头文件和生成的.lib库文件(头文件和库文件与main.c放一起了)

 

如:main.c

#include <stdio.h>
#include <stdlib.h>
#include "libTest.h"
#pragma comment(lib, "./libTest.lib")

int main() 
{ 
    printf("%d\n", myadd(3, 5));

    return 0;
} 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics