TAG:
在做一个应用开发的时候突然发现一个问题,请Linux/Unix的大哥们讲解一下问题原因以及如何避免,谢谢! 状况如下: a.cpp 文件 void init() { pthread_create(&pid, NULL, threadwork, NULL); } void threadwork(void *p) { printf("this is a thread"); } 用g++ -fpic -shared -lc -o liba.so ./src/a.cpp -pthread 编译成动态链接库文件 b.cpp 文件 typedef void (*_initA)(); void threadwork(void *p){ printf("this is b thread"); } int main(...) { void *pdlCoccHandle = dlopen("liba.so", RTLD_NOW); _initA _init = (_initA)dlsym(pdlCoccHandle, "init"); _init(); } 用g++ -fpic -o b ./src/b.cpp -pthread 编译成可执行文件 按照我的想法执行结果应该是输出 但是结果却是 this is b thread 请问这是怎么回事?????我想这应该是函数名字引起的问题,但是虽然两个函数名称相同但是他们所要执行的功能是不一样的(我想在内存中定一的地址也是不一样的)。请问g++对待这种情况是如何编译的?如何能够避免这种情况的发生? --------------------------------------------------------------- 我想可能就是这个原因吧,你打开-Wall 选项看看有没有warning什么的. [align=right][color=#000066][此贴子已经被作者于2007-6-8 12:57:54编辑过][/color][/align] (iwgh) |