文件目錄
operation
|__my_operation.c
|__my_operation.h
my_operation.c文件
#ifndef __MYOPERATION__
#define __MYOPERATION__
#include <iostream>
using namespace std;
int my_sum(int a, int b)
{
return a+b;
}
int my_mul(int a, int b)
{
return a*b;
}
#endif /*__MYOPERATION__*/
my_operation.h文件
#ifndef MYOPERATION_H_
#define MYOPERATION_H_
#ifdef __cplusplus
extern "C" //C++
{
#endif
int my_sub(int a, int b);
int my_mul(int a, int b)
#ifdef __cplusplus
}
#endif
#endif /* MYOPERATION_H_ */
在operation文件夾下打開終端輸入:g++ my_operation.c -fPIC -shared -o my_operation.so,回車;如果在operation文件夾中生成 my_operation.so文件,終端沒有報錯,說明生成成功。
參考:https://blog.csdn.net/ktigerhero3/article/details/68941252