the first part of the Mac OS to create a static library
Preface
As we all know, Mac OS is actually written based on Unix, so it retains many of the original UNIX features, in the case of static libraries, still named after Libxxxx.a. There are many ways to compile a static library under a Mac, such as using Xcode creation and compilation, and you can create and compile directly using the command line (which can be combined with makefile), which will be described in the form of a command line (which can be combined makefile).
In this example, a LIBPERSON.A static library is compiled, which provides a showname function to print out the string "Brian" in the console. Write source file Person.h
The contents of the document are as follows:
#ifndef __person_h__
#define __person_h__
void ShowName ();
#endif
The contents of the source file person.c file are as follows:
#include "person.h"
#include <stdio.h>
#include <stdlib.h>
void ShowName ()
{
printf ("brian./n");
}
compile the static library Libperson.a
$ gcc-c person.c
$ ar-r libperson.a PERSON.O
So far, we have compiled the Libperson.a static library files we need.