文件目录
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