C++进阶5:动态库与静态库--类篇

本文详细介绍了C++中静态库和动态库的制作与使用过程,包括静态库的创建和链接,动态库的生成与加载,并通过修改test.h, test.cpp及main.cpp展示了具体操作步骤。特别讨论了类的动态链接库,强调其只能用于C++调用,以及如何创建和销毁抽象类对象的接口。" 45168821,2078949,使用MATLAB实现PCNN进行图像特征提取,"['图像处理', '神经网络', 'MATLAB编程', '特征提取', 'PCNN模型']
摘要由CSDN通过智能技术生成

0.前提(文件内容)

(1)test.h

#pragma once
class Test{
   
public:
    Test();
    ~Test();
    void Func(int i);
};

(2)test.cpp

#include <iostream>
#include "test.h"
using namespace std;

Test::Test(){
   
    cout << __func__ << "()" << endl;
}
Test::~Test(){
   
    cout << __func__ << "()" << endl;
}
void Test::Func(int i){
   
    cout << __func__ << "(" << i << ")" << endl;
}

(3)main.cpp

#include "test.h"
int main(){
   
    Test t;
    t.Func(100);
}

1、静态库的制作与使用

1.1 创建

(1)编译源文件

g++ -c -o test.o test.cpp

(2)生成静态库

ar -rcs libtest.a test.o

1.2 使用

(1)链接静态库

g++ -o main main.cpp -L. -ltest

或者

g++ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值