如何提供多个链接功能的选项
我有3个对象文件
main.o
general.o
specific.o
。 enstry.o对handle()
,实现通用功能, extile。 我想在我的cmake中指定“搜索要链接到特定的链接
。
I have 3 object files :
main.o
general.o
specific.o
in main.o there is a call to function : void handle(void)
,
general.o implement a generic functionality to handle()
,
specific.o might or might not have an implementation to handle()
,
I want to specify in my cmake that "search to link handle with specific.o if fail then try with general.o"
Is that possible ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标准C ++肯定没有什么可以允许的。
对于GCC/CLANG工具链,您可以将
定义
作为ender>常规
带有__属性__(((弱))
的弱符号, in <代码>特定。但是请非常小心,请确保
handle
本身不会在常规
中调用。因为如果是这样,则可以在链接器看到任何内容之前将呼叫夹住,从而导致某些代码调用常规方法,其余特定于特定于此。链接时间优化实际上可能更安全。There certainly is nothing in standard C++ which allows this.
For Gcc/clang toolchain you can define
handle
as a weak symbol ingeneral
TU with__attribute__((weak))
and as ordinary symbol inspecific
.Be very careful with this though, ensure that
handle
itself is not called ingeneral
. Because if it is, the call might be inlined before the linker sees anything, resulting in some code calling the general method, the rest specific. Link-time optimization might be actually more safe here.