- 论坛徽章:
- 3
|
演示一把:
- linux-0gt0:/tmp/ch/b # cat test.c
- int func(int i)
- {
- return i+1;
- }
- linux-0gt0:/tmp/ch/b # cat main.c
- #include <stdio.h>
- int func(int);
- int main()
- {
- printf("%d\n",func(1));
- return 0;
- }
- linux-0gt0:/tmp/ch/b # gcc -shared -Wl,-soname,libtest.so -o libtest.so test.c
- linux-0gt0:/tmp/ch/b # gcc -c main.c
- linux-0gt0:/tmp/ch/b # gcc main.o -L. -ltest -o test
- linux-0gt0:/tmp/ch/b # ./test
- ./test: error while loading shared libraries: libtest.so: cannot open shared object file: No such file or directory
- linux-0gt0:/tmp/ch/b # mv libtest.so /lib
- linux-0gt0:/tmp/ch/b # ./test
- 2
复制代码 |
|