lib + class

   本文介绍下将class类封装成dll/lib库的方法
    关键点:添加declspec(dllexport) 
一、封装成动态库 test.dll
     步骤1: 写代码
   ----- test.h
    #pragma once
    class  declspec(dllexport)  CTest
{
public:
    CTest();
  ~Ctest();
  
    void Test();
}
 
 ---- test.cpp

   void Test()
{
     printf("hello world");
}

    步骤2:编译生成dll
    编译器生成或命令行生成

    步骤3:调用  需要test.h+test.lib+test.dll
    ---main.cpp

    #include "test.h"
    #pragma comment(lib, "test.lib")
    void main()
{
CTest test;
test.Test();
}

   步骤4:编译测试 main.cpp


二、封装成静态库 test.lib
  关键点:不要declspec(dllexport) 
  其步骤同方法一
     其中 步骤1 需要需改:      class  CTest
           步骤3需要需改:调用  需要test.h+test.lib
    
参考:http://blog.youkuaiyun.com/bodybo/article/details/39054239#comments
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值