linux下编写动态库以及使用动态库 下载本文

内容发布更新时间 : 2024/6/16 12:54:35星期一 下面是文章的全部内容请认真阅读。

在Linux环境下编写和使用静态函数库

1. h 文件 /*

* libsth.h

* Declarations for simple error-handling library //声明简单的错误处理库 */

#ifndef _LIBSTH_H #define _LIBSTH_H

#include \ //标准参数 //加减乘除函数 /* * ADD */

int ADD(int a, int b); /*

* SUBSTRACT */

int SUBSTRACT(int a, int b);

/* * TIMES */

int TIMES(int a, int b); /*

* DIVIDE */

float DIVIDE(int a, int b); #endif

2. c 文件 /*

* libsth.C

* Implementation of the functions defined in libsth.h //实现h中定义的函数 */

#include \#include \#include \#include \

#include \

int ADD(int a, int b) {

return a + b; }

int SUBSTRACT(int a, int b) {

return a - b; }

int TIMES(int a, int b) {

return a * b; }

float DIVIDE(int a, int b) //未对入口参数进行适当的判断,可能产生错误 {

return (float)((float)a / (float)b); }