vs 生成第三方库文件 以及 调用第三方库文件

vs 生成第三方库文件

1 新建项目

vs 生成第三方库文件 以及 调用第三方库文件_第1张图片

在应用程序设置中选择静态库,点击完成
vs 生成第三方库文件 以及 调用第三方库文件_第2张图片

2 添加文件

a 在头文件中添加 libtest.h文件,写入:

#ifndef LIBTEST_H  
#define LIBTEST_H  

int sum(const int x, const int y);
int sub(const int x, const int y);

#endif  

b 在源文件中添加 libtest.cpp文件 ,写入

#include "stdafx.h"

#include "libtest.h"  

int sum(const int x, const int y)
{
    return x + y;
}

int sub(const int x, const int y)
{
    return x - y;
}

c 右键解决方案,点击生成。

d 在工程目录下即可生成可以使用的第三方库文件:libtest.h 和libtest.lib。


vs 调用第三方库文件

1 新建项目,在项目目录文件夹下新建两个文件夹 include 和lib。

  • include文件夹用来存放头文件,如 libtest.h
  • lib 文件夹用来存放库文件,如 libtest.lib
    分别拷入对应文件到相应文件夹下。

2 配置路径

  • 打开属性页面 配置属性—->VC++目录
  • 包含目录 写入 include路径
  • 库目录 写入 lib路径
    vs 生成第三方库文件 以及 调用第三方库文件_第3张图片

3 配置库文件

  • 配置属性—->连接器—->输入—->附加依赖项
    vs 生成第三方库文件 以及 调用第三方库文件_第4张图片
    即可完成第三方库目录的配置。

4 调用第三方库目录

#include "stdafx.h"
#include "libtest.h"   //引用第三方库的   头文件
#include   
int _tmain(int argc, _TCHAR* argv[])
{

    std::cout << sum(3, 5) << std::endl;  //调用第三方库的方法即可
    std::cout << sub(4, 1) << std::endl;
    return 0;
}

你可能感兴趣的:(软件配置)