~/so_test $ cat testlib.h
#ifndef __LIB_TEST_H__
#define __LIB_TEST_H__
void libxx();
#endif
~/so_test $ cat testlib.c
#include <stdio.h>
#include <stdlib.h>
void libxx()
{
printf("come from libxx.so\n");
}
~/so_test $ cat main.c
#include "testlib.h"
#include <stdlib.h>
#include <stdio.h>
#if 0
void libxx()
{
printf("come from prg!\n");
}
#endif
int main(int argc, char *argv[])
{
libxx();
return 0;
}
~/so_test $ gcc -fpic -shared -o libtest.so testlib.c
~/so_test $ gcc -l/home/admin/so_test -o main.o -c main.c
~/so_test $ gcc -o main -L/home/admin/so_test main.o -ltest
如果程序中有 libxx 这个函数 运行的时候调用的是程序中的, 如果 程序中没有这个函数那么就调用库里面的