2013-03-13 46 views
0

我使用名为GLC的C库以编程方式记录我的OpenGL缓冲区。 GLC监听按键,这不是一个真正的以编程方式触发的很好的解决方案。使本地c库函数全局可访问

因此,我想通过我的软件中的函数调用从GLC执行记录。 我的C++软件正在链接到包含所需函数start_capture()的库。通过nm我可以看到这个功能是本地的,标记为小写字母t。

既然它必须是全局的,才能在我的软件中访问它,所以我想重新编译库(我已经完成了)。但是我不知道什么改变,使其接近....

这里是start_capture()声明,在头文件lib.h

... 
__PRIVATE int start_capture(); // No idea where the __PRIVATE is coming from 
... 

这是在定义/执行start_capture()功能在main.c

int start_capture() 
... 
return ret; 
} 

,这是我的dlopen得到功能:

void *handle_so; 
void (*start_capture_custom)(); 
char *error_so; 
handle_so = dlopen("/home/jrick/fuerte_workspace/sandbox/Bag2Film/helper/libglc-hook.so", RTLD_LAZY); 
if (!handle_so) 
{ 
    fprintf(stderr, "%s\n", dlerror()); 
    exit(1); 
} 
dlerror(); /* Clear any existing error */ 
start_capture_custom = (void (*)())dlsym(handle_so, "start_capture"); 
if ((error_so = dlerror()) != NULL) 
{ 
    fprintf(stderr, "%s\n", error_so); 
    exit(1); 
} 
start_capture_custom(); 
dlclose(handle_so); 
start_capture(); 

那么,我应该改变什么来通过库文件访问它?

我希望这足以说明问题的清楚。如果没有,我会尽可能快地回答。

回答

1

__PRIVATE是一个#define用于隐藏符号的GCC扩展。定义见https://github.com/nullkey/glc/blob/master/src/glc/common/glc.h#L60,关于GCC扩展的更多信息请参考http://gcc.gnu.org/wiki/Visibility

https://stackoverflow.com/a/12011284/2146478提供了一种解决方案,可以在不重新编译的情况下取消隐藏符号。你会想要做这样的事情:

$ objcopy --globalize-symbol=start_capture /path/to/your/lib.a /path/to/new/lib.a 
+0

谢谢你的帮助。 我将参数更改为__PUBLIC,它工作得很好。 – Josch 2013-03-13 15:19:37