是否可以链接到共享库而不访问库本身? [英] Is it possible to link to a shared library without access to the library itself?

查看:73
本文介绍了是否可以链接到共享库而不访问库本身?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有共享库的头文件,但没有共享库或其源代码.

I have the header files of a shared library but not the shared library nor its source code.

我仍然可以针对该库编译一些代码吗?

Can I still compile some code against this library?

如果没有,则共享库包含哪些信息而不包含在标头中?

If not, what information does the shared library contain which is not in the headers?

推荐答案

我仍然可以针对该库编译一些代码吗?

Can I still compile some code against this library?

编译:是的.链接:也许吧.

Compile: yes. Link: maybe.

您可以创建一个虚拟库进行链接.例如.如果标题包含:

You can create a dummy library to link against. E.g. if the header contains:

int library_func(void*);

然后:

// dummy_lib.c
int library_func(void *p) { return 0; }

gcc -fPIC -shared -o libfoo.so dummy_lib.c

# Now you can use libfoo.so to link your program.

有一些陷阱:

  1. 真实库中的 SONAME 可能不是 libfoo.so (例如, libfoo.so.2 ).如果没有访问真正的 libfoo 的话,您将无法知道.
  2. 真实库可以使用版本化符号.如果您将程序链接到虚拟库,它将使用所有引用符号的默认版本,该版本现在可能正确,但是将来可能会中断(如果/当真实库使用新的和不兼容调用的任何符号).
  1. The real library may have SONAME of something other than libfoo.so (e.g. libfoo.so.2). There is no way for you to know without access to the real libfoo.
  2. The real library could use versioned symbols. If you link your program against the dummy library, it will use default version of all referenced symbols, which is likely to be correct now, but is likely to break in the future (if/when the real library is updated with a new and incompatible implementation of any symbols you call).

这篇关于是否可以链接到共享库而不访问库本身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆