- 论坛徽章:
- 0
|
求助: 关于共享库的用法
//test.h
void liblink();
//test.c
void liblink()
{pirntf("link ok" ;}
//main.c
int main()
{
liblink();
}
$gcc -fPIC -g -c test.c -o libtest.o
$gcc -g -shared -Wl ,-soname,libtest.so -o libtest.so.1.0.0 libtest.o;
$ln -s libtest.so.1.0.0 llibtest.so.1; //use for soname
$ln -s libtest.so.1.0.0 libtest.so; //use for -ltest linking.
$gcc -g main.c -o main -L /myown/test/ -ltest;
//in order to execute the program ,you must set.
$$LD_LIBRARY_PATH=$(pwd) ./main; //$(pwd) have libtest.so |
|