链接器剥离未使用的类
我正在 C++ 中的跨平台项目上工作,在 IOS 和 Android 下,我遇到以下情况 :
我正在编写一个库,用于直接从描述场景图的 xml 文件加载场景图。该库有一个基本树节点类,它实现了使类可通过其名称构造的所有功能。然后实现附加的树节点,所有节点都派生自该基节点类。这工作得很好,但有一个问题。链接器“认为”我的一些类不会被使用,并将它们从库中删除。我现在有一个令人讨厌的解决方法,有一个包含所有现有节点标头的文件,并且在该文件中创建并更改每个节点的一个实例,以指示编译器/链接器确实正在使用该类。
有谁知道一个好的设计模式可以用来自动生成所有类所需的实例?
我尝试创建放置到类 cpp 文件中的宏,该文件创建给定类的静态实例,但链接器仍然检测到这些静态实例永远不会被引用。
或者是否有一个链接器标志可用于告诉链接器不要删除任何未使用的类?就像已经提到的:我正在 Android (ndk 6.0) 和 IOS (xcode 4.2) 上工作,
这个问题不会成为我的项目的阻碍,但在这里找到一个可接受的解决方案真的很高兴。
I am working on a cross platform project in C++, under IOS and Android, and I am having the following situation
:
I am writing a library used to load scene graphs directly from xml files describing them. The library has a base tree node class, that implements all the functionality to make a class constructable by it's name. Then additional tree nodes are implemented, all deriving from this base node class. This works excellent but there is one problem. The linker 'thinks' that some of my classes are not going to be used and strips them out of the library. I have a nasty workaround right now, having a file that includes all existing nodes headers, and in this file one instance of every node is being created and altered to indicate the compiler/linker that this class is really being used.
Does anybody know a good design pattern that can be used to automatically generate the required instances of all classes?
I have tried to create macros that are placed into the classes cpp file that creates a static instance of the given class, but the linker still detects that those static instances are never going to be referenced.
Or is there a linker flag that can be used to tell the linker not to strip any unused classes out? Like already mentioned: I am working on Android (ndk 6.0) and on IOS (xcode 4.2)
This problem is not going to be a showstopper for my project but it would really be nice to find an acceptable solution here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,没有标准的方法来保证这些对象的构造,只能将它们全部列出在一个特定的位置。
Therefore there's no standard way to guarantee the construction of those objects but to list them all in one specific place.