Compile the. A library file used by Linux
The first is the source file that needs to be compiled into. A
hello.h :
#ifndef __include_hello_h__#define __include_hello_h__void HELLO (const char *name); #endif//End __include_hello_h__
hello.c
#include "stdio.h" void Hello (const char *name) { printf ("Hello World%s\n", name);}
and A in Linux test on the platform . main.c
#include "hello.h" int main () { Hello ("everyone"); return 0;}
Test on Linux, compile into. A files, mainly using. o Files and AR commands
1. First generate. o File:
Gcc-c hello.c
In this way, the source code directory will produce a hello.o
2. Use the AR command to create a. A file from the. o File
AR cr libhello.a hello.o
This makes it possible to generate. A files, Note that the first three bits of the . A file to be generated are preferably lib, otherwise the library may not be found at the time of the link
3, under the Linux test use
Compile the MAIN.C and let hello.a link to main
GCC main.c-l.-lhello-o main( Note that There is a. After -l)
So that in the face of the directory there is an executable program main, direct operation is the result of our request
Compile the. A library file used by Linux