ld 的奇怪警告

发布于 2024-12-10 08:48:43 字数 1572 浏览 1 评论 0原文

当我构建程序时,我收到了来自 ld 的警告:

ld:警告:在全局构造函数中直接访问_ZN12_GLOBAL__N_143ensure_log_is_created_before_maing_l_filterEto全局弱符号vtable for cs::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 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.

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

つ可否回来 2024-12-17 08:48:43

这可能是由于使用不同的可见性设置编译不同的翻译单元造成的。

即您更改了一些标头,并且没有对整个项目进行完整重新构建。现在就这样做。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文