- 论坛徽章:
- 0
|
我在hp 11下写了一个动态库的程序,运行正常,但退出时coredump。请各位大侠指点。
我的动态库程序libtest.cpp如下:
- #include <iostream.h>;
- extern "C" {
- int memory ( )
- {
- cout << "Enter Share Lib" << endl;
- return 1;
- }
- }
复制代码
我的主程序main.cpp如下:
- #include <stdio.h>;
- #include <dl.h>;
- #include <stdlib.h>;
- #include <unistd.h>;
- int main ( int argc , char **argv )
- {
- shl_t hndl;
- int (*memory)();
-
- if ((hndl = shl_load("/home/test/yh/stl/bas1/libtest.sl",BIND_IMMEDIATE| BIND_NONFATAL, 0L)) == NULL)
- perror("shl_load: error loading libtest.sl"), exit(1);
-
- if (shl_findsym(&hndl, "memory", TYPE_PROCEDURE,(void *) &memory))
- perror("shl_findsym: error loading libtest.sl"), exit(1);
-
- printf("ret := %d\n" , (*memory)() );
-
- shl_unload(hndl);
- printf("close share lib\n");
- exit(0);
- }
复制代码
编译命令如下:
- aCC +DA2.0W -c +Z libtest.cpp
- ld -E -b -o libtest.sl libtest.o
- aCC +DA2.0W main.cpp -o main -ldld
复制代码
运行结果如下:
- $ ./main
- Enter Share Lib
- ret := 1
- close share lib
- Memory fault(coredump)
复制代码
请问这是为什么? |
|