linux上编译动态库及其调用
//.h
#ifndef _H_A
#define _H_A
class test
{
public:
void function();
};
#endif
//.cpp
#include <iostream>
#include "a.h"
using namespace std;
void test::function()
{
cout << "test::function" << endl;
}
//main.cpp
#include <iostream>
#include "a.h"
#include "b.h"
#g++ -o libab.so -fPIC -shared a.cpp b.cpp -I.
#g++ -o main mian.cpp -L. -lab
using namespace std;
int main()
{
test t;
t.function();
//cs s;
//s.function();
return 0;
}
代码下载:
https://github.com/18971492243/coding.git