将不同版本的静态库中的符号分开

发布于 2024-11-15 18:52:54 字数 1046 浏览 1 评论 0原文

我有一个静态 Objective-C++ 库 basic.a,带有函数 BasicFunction()。静态 Objective-C++ 库 foo.abar.a 依赖于 basic.a 并具有函数 Foo()Bar() 调用 BasicFunction()

这是棘手的部分:当我创建一个链接 foo.abar.a 的项目时,每个项目都在不同的时间构建,我想要 Foo() 调用构建时的 BasicFunction() 版本,Bar() 调用 BasicFunction()< 版本/code> 当时就在那里建造的。 (这样新的库就不会链接到缺少错误修复的旧 BasicFunction() 中。)

现在发生的情况是 Foo()Bar () 都调用相同版本的 BasicFunction(),即 foo.abar.a< 中的任意一个版本。 /strong> 中第一个链接的 项目。更改符号可见性似乎不起作用,因为如果隐藏 BasicFunction() ,它就会隐藏在 basic.a 中,并且 foo.a< 无法看到/strong> 或 bar.a

如果没有好的方法让库调用不同版本的 BasicFunction(),我怎样才能至少检测到问题呢?我尝试过一个哨兵类,它看起来确保它只初始化一次,但链接器似乎将不同版本的 basic.a 中的两个哨兵优化为一个,再次来自哪个库首先链接。

I have an static Objective-C++ library basic.a, with a function BasicFunction(). Static Objective-C++ libraries foo.a and bar.a depend on basic.a and have functions Foo() and Bar() that call BasicFunction().

Here's the tricky part: When I make a project that links in foo.a and bar.a, each built at a different time, I want Foo() to call the version of BasicFunction() that was there when it was built, and Bar() to call the version of BasicFunction() that was there when it was built. (This is so that newer libraries will not link in an old BasicFunction() that is missing bug fixes.)

What's happening now is that Foo() and Bar() both call the same version of BasicFunction(), the one that is in whichever of the two foo.a and bar.a that is linked first in the project. Changing symbol visibility does not seem to work because if BasicFunction() is hidden, it's hidden in basic.a and can't be seen by foo.a or bar.a.

If there is no good way to make the libraries call different versions of BasicFunction(), how can I at least detect the problem? I've tried a sentinel class that looks to make sure it only gets initialized once, but the linker seems to optimize the two sentinels in different builds of basic.a into just one, again from whichever library that is linked first.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜兔 2024-11-22 18:52:54

好吧,其他人不太可能遇到这个特殊问题,但解决方案是从普通 C 函数调用 Objective-C 哨兵类,每个构建都有唯一的名称,由每个库调用。哨兵类确保在运行时只有一个具有其名称的实例。

Well, it's unlikely anyone else will have this particular problem, but the solution was to have an Objective-C sentinel class called from a plain C function, both with unique names per build, called by each library. The sentinel class ensures there is only one instance with its name at runtime.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文