- 论坛徽章:
- 0
|
我编写了一个动态库,想验证其有效性,但出现了一些问题.请大虾们指点一下:
我的代码如下:
/* lt.c
*
*/
#include <stdio.h>
void myprint(void)
{
printf("Linux library test!\n");
}
/* lt.h
*
*/
void myprint(void);
/* test.c
*
*/
#include "lt.h"
int main(void)
{
myprint();
return 0;
}
做成动态库:
做成动态库 liblt.so 。
1. $ gcc -c lt.c -o lt.o
2. $ gcc -shared -Wall -fPIC lt.o -o liblt.so
连接动态库:
gcc -o test test.c -L./ -llt
然后把liblt.so拷到/usr/lib目录下.
当执行测试时,出现了下列信息,不知道是什么原因:
./test
./test: error while loading shared libraries: /usr/lib/liblt.so: cannot restore segment prot after reloc: Permission denied |
|