ld 的奇怪警告
当我构建程序时,我收到了来自 ld 的警告:
ld:警告:在全局构造函数中直接访问
_ZN12_GLOBAL__N_143ensure_log_is_created_before_maing_l_filterEto
全局弱符号vtable forcs::ObjectFactoryAliasInstantiation
意味着弱符号不能被在运行时被覆盖。这可能是由于使用不同的可见性设置编译不同的翻译单元所致。
引用错误的代码是这样的:
class ObjectFactory {
public :
ObjectFactory(const char *alias):sAlias(alias){};
std::string sAlias;
virtual void* createInstance() = 0;
};
template <class T>
class ObjectFactoryAliasInstantiation : public ObjectFactory{
public:
ObjectFactoryAliasInstantiation(const char *alias):ObjectFactory(alias){};
void* createInstance() { return (void*)new T(&sAlias); };
};`
和这样:
/*
Class for register the dispatcher for the command
*/
class CommandDispatcherRegister {
public:
CommandDispatcherRegister(ObjectFactory *commandFactory);
};
/*
Macro for help the Command Dispatcher classes registration
*/
#define REGISTER_AND_DEFINE_COMMAND_DISPATCHER_CLASS(CMD_CLASS_NAME) class CMD_CLASS_NAME;\
static const CommandDispatcherRegister CMD_CLASS_NAME ## CommandDispatcherRegister(new ObjectFactoryAliasInstantiation<CMD_CLASS_NAME>(#CMD_CLASS_NAME));\
class CMD_CLASS_NAME : public CommandDispatcher\
结束这样:
REGISTER_AND_DEFINE_COMMAND_DISPATCHER_CLASS(DefaultCommandDispatcher) {
bool deinitialized;
I received this warning from ld
whe I was buliding my program:
ld: warning: direct access in global constructors keyed to
_ZN12_GLOBAL__N_143ensure_log_is_created_before_maing_l_filterEto
global weak symbol vtable forcs::ObjectFactoryAliasInstantiation<cs::DefaultCommandDispatcher>
means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.
The code witch refer the error is this:
class ObjectFactory {
public :
ObjectFactory(const char *alias):sAlias(alias){};
std::string sAlias;
virtual void* createInstance() = 0;
};
template <class T>
class ObjectFactoryAliasInstantiation : public ObjectFactory{
public:
ObjectFactoryAliasInstantiation(const char *alias):ObjectFactory(alias){};
void* createInstance() { return (void*)new T(&sAlias); };
};`
and this:
/*
Class for register the dispatcher for the command
*/
class CommandDispatcherRegister {
public:
CommandDispatcherRegister(ObjectFactory *commandFactory);
};
/*
Macro for help the Command Dispatcher classes registration
*/
#define REGISTER_AND_DEFINE_COMMAND_DISPATCHER_CLASS(CMD_CLASS_NAME) class CMD_CLASS_NAME;\
static const CommandDispatcherRegister CMD_CLASS_NAME ## CommandDispatcherRegister(new ObjectFactoryAliasInstantiation<CMD_CLASS_NAME>(#CMD_CLASS_NAME));\
class CMD_CLASS_NAME : public CommandDispatcher\
end this:
REGISTER_AND_DEFINE_COMMAND_DISPATCHER_CLASS(DefaultCommandDispatcher) {
bool deinitialized;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是由于使用不同的可见性设置编译不同的翻译单元造成的。
即您更改了一些标头,并且没有对整个项目进行完整重新构建。现在就这样做。
This was likely caused by different translation units being compiled with different visibility settings.
i.e. you changed some headers and didn't do a full re-build of your whole project. Do that now.