Ubuntu 16.04环境下QT生成so(动态链接库)

Ubuntu 16.04环境下QT生成so(动态链接库),
并新建QT项目调用so文件
1.首先是新建一个工程,选择Library ,然后选择Library C++库,打开后是这样的:在这里插入图片描述

2.选择 “choose”,命名为“plugintest”(后面的plugintest即为同样流程建立的文件,plugintest0为了演示重新新建的项目)
在这里插入图片描述

3.点“next”之后,得到下图
在这里插入图片描述

4.继续“next”,得到下图
在这里插入图片描述

5.点“finish”,得到一个“plugintest”的工程,然后点菜单栏“build”的“rebuild project“plugintest””,然后点左下角的绿色三角按钮编译运行。在这里插入图片描述

6.在plugintest.h修改为如下代码(红色为添加的代码):

#ifndef PLUGINTEST_H
#define PLUGINTEST_H
#include "plugintest_global.h"
class PLUGINTESTSHARED_EXPORT plugintest
{

public:
    plugintest();
    void helloworld();//新加入
};
#endif // PLUGINTEST_H

7.在plugintest.cpp修改为如下代码(红色为添加的代码):

#include "plugintest.h"
#include <iostream>
using namespace std;
plugintest::plugintest()
{

}
void plugintest::helloworld()//新加入
{//新加入
    cout<<"hello world"<<endl;//新加入
}//新加入

8.再一次编译运行plugintest,项目的debug文件夹生成下面这些文件:(此时有弹出如下为成功)
在这里插入图片描述

9.新建C++项目,步骤:new project->non-qt project->plain c++ application->choose,然后一直next,直至新建到项目。
10.鼠标右击项目insert_to文件夹,选择“add library”,得到下图,选“next”(把生成的libplugintest.so文件和plugintest.h文件放在insert_to文件夹里):
在这里插入图片描述

10.得到类似与下图library file选刚才的So文件,include path选insert_to文件夹
在这里插入图片描述

11.一直next得到下图pro文件的截图
在这里插入图片描述
在这里插入图片描述

12.修改main.cpp,红色代码为加入新的内容,至此,调用完毕!

#include <iostream>
#include "plugintest.h"//包含plugintest.h头文件//新加入
using namespace std;//新加入
int main()
{
    //cout << "Hello World!" << endl;
    plugintest test;//PluginTest是plugintest.h中定义的类名//新加入
    test.helloworld();//调用helloworld//新加入
    return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值