so_test.h:
#include <stdio.h>
#include <stdlib.h>
void test_a();
void test_b();
void test_c();
test_a.c:
#include "so_test.h"
void test_a()
{
printf("this is in test_a...\n");
}
test_b.c:
#include "so_test.h"
void test_b()
{
printf("this is in test_b...\n");
}
test_c.c:
#include "so_test.h"
void test_c()
{
printf("this is in test_c...\n");
}
run.sh
#!/bin/sh
echo $LD_LIBRARY_PATHexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. 导入共享库到环境变量中,一次性的。
echo $LD_LIBRARY_PATH
gcc test_a.c test_b.c test_c.c -fPIC -shared -o libtest.so 生成共享库
gcc test.c -o test libtest.so 使用共享库
ldd ./test 显示程序链接的共享库
./test
Makefile 文件
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./ipp64so:.
all: tsd_silence
CC = g++
#CFLAGS = -g -Wall -ansi
INCLUDE = -I./ -I./IPP6EM64/include/
IPPLIB = -L./ipp64so/ -L.
THREAD = -lpthread
tsd_silence: tsd_silence.o voicedetect.o CPcm.o TSD_API.so
$(CC) $(IPPLIB) $(THREAD) tsd_silence.o voicedetect.o CPcm.o TSD_API.so -o tsd_silence
tsd_silence.o: tsd_silence.c voicedetect.h
$(CC) $(INCLUDE) -c tsd_silence.c
voicedetect.o: voicedetect.c voicedetect.h
$(CC) $(INCLUDE) -c voicedetect.c
CPcm.o: CPcm.c CPcm.h types.h
$(CC) $(INCLUDE) -c CPcm.c
clean:
rm -rf *.o tsd_silence