Visual Studio 中的 GCC 风格弱链接?

GCC style weak linking in Visual Studio?(Visual Studio 中的 GCC 风格弱链接?)
本文介绍了Visual Studio 中的 GCC 风格弱链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

GCC 有能力通过 __attribute__((weak)) 弱化符号链接.我想在用户可以在其应用程序中覆盖的静态库中使用弱符号.GCC 风格的弱符号可以让我这样做,但我不知道是否可以用 Visual Studio 来完成.

GCC has the ability to make a symbol link weakly via __attribute__((weak)). I want to use the a weak symbol in a static library that users can override in their application. A GCC style weak symbol would let me do that, but I don't know if it can be done with visual studio.

Visual Studio 是否提供类似的功能?

Does Visual Studio offer a similar feature?

推荐答案

MSVC++ 有 __declspec(selectany) 它涵盖了弱符号的部分功能:它允许你定义多个相同的符号与外部链接,指示编译器选择几个可用的任何一个.但是,我认为 MSVC++ 没有任何东西可以涵盖弱符号功能的另一部分:在库中提供可替换"定义的可能性.

MSVC++ has __declspec(selectany) which covers part of the functionality of weak symbols: it allows you to define multiple identical symbols with external linkage, directing the compiler to choose any one of several available. However, I don't think MSVC++ has anything that would cover the other part of weak symbol functionality: the possibility to provide "replaceable" definitions in a library.

顺便说一句,这让人想知道对标准可替换 ::operator new::operator delete 函数的支持在 MSVC++ 中是如何工作的.

This, BTW, makes one wonder how the support for standard replaceable ::operator new and ::operator delete functions works in MSVC++.

这篇关于Visual Studio 中的 GCC 风格弱链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
STL BigInt class implementation(STL BigInt 类实现)
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)