我从 ld
收到了这个警告当我构建我的程序时:
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.
错误的代码是这样的:
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;
最佳答案
这可能是由于使用不同的可见性设置编译的不同翻译单元造成的。
即您更改了一些 header 并且没有对整个项目进行完整 重建。现在就做。
关于c++ - ld 的奇怪警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7785912/