c++动态编译 并调用

c++编译为动态库,并调用;实现封装到cpp里面,经过so使用html

头文件linux

# test.h
#ifndef CIRCLE_H
#define CIRCLE_H

#include <iostream>
using namespace std;
class Demo
{
public:
    int do_mapping(std::string r, int m, bool e, int type);
};

#endif

 实现ios

#test.cpp
#include "Demo.h"
using namespace std;

int Demo::do_mapping(std::string r, int m, bool e, int type){
	std::cout << "r:" << r<< std::endl;
	std::cout << "m:" << m<< std::endl;
	std::cout << "e:" << e<< std::endl;
	std::cout << "type" << type << std::endl;
	return 1;
}

 

测试 main.cpp:c++

#include <iostream>
#include "Demo.cpp"
int main( ){
	Demo* demo = new Demo();
    demo->do_mapping("a",100,true,0);
    cout<<"end"<<endl;
    return 0;
}

调用app

g++ main.cpp

  

编so 动态连接库(名字:开头 lib, so结尾)测试

g++ Demo.cpp -fPIC -shared -o libdemo.so

调用动态链接库 testso.cppspa

#include <iostream>
#include "Demo.h"
int main( ){
	Demo* demo = new Demo();
    demo->do_mapping("a",100,true,0);
    cout<<"end"<<endl;
    return 0;
}

  调用so(头文件 *.h 须要和so放到一个目录中)htm

g++ testso.cpp  -L. -ldemo -o o.txt
more o.txt

  

 

参考:blog

https://www.cnblogs.com/wnnily/articles/4565237.htmlget

https://www.linuxidc.com/Linux/2012-09/70502.htm

相关文章
相关标签/搜索