【发布时间】:2011-12-08 19:29:19
【问题描述】:
我在构建程序时收到了来自ld 的警告:
ld:警告:在全局构造函数中直接访问键控到
_ZN12_GLOBAL__N_143ensure_log_is_created_before_maing_l_filterEto全局弱符号 vtable 的cs::ObjectFactoryAliasInstantiation<cs::DefaultCommandDispatcher>意味着弱符号在运行时不能被覆盖。这可能是由于使用不同的可见性设置编译不同的翻译单元造成的。
参考错误的代码是这样的:
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;
【问题讨论】:
-
您检查过链接器向您建议的内容吗?
-
是的,但我不知道要检查什么......
-
而
This was likely caused by different translation units being compiled with different visibility settings并没有暗示要检查什么? -
这是什么
ensure_log_is_created_before_maing_l_filter? -
您能显示
ensure_log_is_created_before_maing_l_filter或cs::ObjectFactoryAliasInstantiation的任何代码吗?