Ubuntu生成動態鏈接庫

文件目錄

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章