Linux also has a static/dynamic link library like Windows systems, and here's how to create and use it:
Let's say there are several files:
Header file String.h, declare the correlation function prototype, the contents are as follows:
STRLEN.C: The implementation of the function Strlen, gets the length of the given string, as follows:
STRLNEN.C: The implementation of the function Strnlen, gets the length of the given string, returns the maximum length if the length of the input string is greater than the specified maximum length, or returns the actual length of the string, as follows:
To generate a static library:
Use GCC to generate the corresponding target file:
Gcc–c strlen.c STRNLEN.C
If the corresponding file is not wrong, GCC compiles the file to generate STRLEN.O and STRNLEN.O two target files (equivalent to the obj file under Windows). Then use AR to create a library file named Libstr.a, and insert the contents of STRLEN.O and STRNLEN.O into the corresponding library file. , the relevant commands are as follows:
AR–RC LIBSTR.A STRLEN.O STRNLEN.O
After the command was successfully executed, the corresponding static library LIBSTR.A has been successfully generated.
<span style= "FONT-SIZE:18PX;" ><strong>/*********************************** filename:string.h Description:Author:HCJ date:200
6-5-7 ************************************/int Strlen (char *pstr);
int Strnlen (char *pstr, unsigned long ulmaxlen); /************************************** filename:get string length Description:Author:HCJ Date : 2006/5/7 **************************************/#include <stdio.h> #include <assert.h> int Strlen
(Char *pstr)
{unsigned long ullength;
ASSERT (NULL!= pstr);
ullength = 0;
while (*pstr++) {ullength++;
return ullength; } ********************************************** fileneme:mystrnlen.c Description:get input String Length,if string Large max length input return max length, else real length Author: Hcj
Date:2006-5-7 **********************************************/#include <stdio.h> #include <assert.
h> int Strnlen (char *pstr, unsigned long ulmaxlen) {unsigned long ullength;
ASSERT (NULL!= pstr);
if (Ulmaxlen <= 0) {printf ("wrong Max length!\n");
return-1;
} ullength = 0;
while (*pstr++ && ullength < Ulmaxlen) {ullength++;
return ullength; } </strong></span>
This article URL address: http://www.bianceng.cn/OS/Linux/201410/45420.htm