C++ 使本地c库函数全局可访问

C++ 使本地c库函数全局可访问,c++,dynamic,local,dynamic-linking,dlopen,C++,Dynamic,Local,Dynamic Linking,Dlopen,我正在使用一个名为GLC的C库以编程方式记录OpenGL缓冲区。 GLC监听按键,这并不是一个真正好的以编程方式触发的解决方案 因此,我希望通过软件中的函数调用从GLC执行录制。 我的C++软件链接到库,其中包含了所需函数 StasyCopCuthSub()/Cuth>。通过nm,我可以看到这个函数是本地的,用小写字母t标记 因为它必须是全局的才能在我的软件中访问它,所以我想重新编译这个库(我已经完成了)。但我不知道该做些什么来让它变得容易 下面是头文件中的start\u capture()中的

我正在使用一个名为GLC的C库以编程方式记录OpenGL缓冲区。 GLC监听按键,这并不是一个真正好的以编程方式触发的解决方案

因此,我希望通过软件中的函数调用从GLC执行录制。 我的C++软件链接到库,其中包含了所需函数<代码> StasyCopCuthSub()/Cuth>。通过nm,我可以看到这个函数是本地的,用小写字母t标记

因为它必须是全局的才能在我的软件中访问它,所以我想重新编译这个库(我已经完成了)。但我不知道该做些什么来让它变得容易

下面是头文件中的
start\u capture()
中的声明

以下是中的
start\u capture()
函数的定义/实现:

这是我的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();
那么,要通过库文件访问它,我应该做什么更改


我希望这足以说明问题。如果没有,我会尽快回答。

\uuu PRIVATE
是一个用于隐藏符号的GCC扩展的
\define
。有关GCC扩展的定义和更多信息,请参阅

提供无需重新编译即可取消隐藏符号的解决方案。您可能希望执行以下操作:

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

谢谢你的帮助。我将参数改为_upublic,效果很好。
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();
$ objcopy --globalize-symbol=start_capture /path/to/your/lib.a /path/to/new/lib.a