#静态库
1. vi demo.h
void demo ( void );
vi demo.c
#include <stdio.h>
#include "demo.h"
void demo ( void )
{
printf( "hello world/n" );
return;
}
2. g++ -Wstrict-prototypes -Wall -Wunused -O3 -c demo.c -o demo.o
file demo.o
3. ar -rsv libdemo.a demo.o
a - demo.o
file libdemo.a
nm -s libdemo.a
ar -tv libdemo.a
4. vi scz.c
#include <stdio.h>
#include "demo.h"
int main ( int argc, void * argv[] )
{
demo();
return 0;
}
5. g++ scz.c -L. -ldemo -Wstrict-prototypes -Wall -Wunused -O3 -o scz
#动态库
1. vi demo.h
void demo ( void );
vi demo.c
#include <stdio.h>
#include "demo.h"
void demo ( void )
{
printf( "hello world/n" );
return;
}
2. gcc -c -fPIC demo.c -O3 -o demo.o
3. gcc -shared -Wl,-soname,libdemo.so.1 -O3 -o libdemo.so.1.0 demo.o
4. ln -sf libdemo.so.1.0 libdemo.so.1
5. ln -sf libdemo.so.1 libdemo.so
6. gcc -L. -lbsd -ldemo -O3 -o scz scz.c