gpt4 book ai didi

c++ - ld 的奇怪警告

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:24:51 25 4
gpt4 key购买 nike

我从 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 for cs::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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com