【问题标题】:Strange warning with ldld 的奇怪警告
【发布时间】: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_filtercs::ObjectFactoryAliasInstantiation 的任何代码吗?

标签: c++ gcc warnings ld


【解决方案1】:

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

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

【讨论】:

  • 我也使用 scons 作为我的项目(我使用 Xcode,但使用 scons 分发它),如果我运行 scons -c 然后运行 ​​scones,我也会收到此警告。无论如何我会再试一次
  • 这不是您从更改标头中得到的警告,而是从使用不匹配的 -fvisibility 设置编译目标时得到的警告。见stackoverflow.com/a/9954259/48125
猜你喜欢
  • 2012-04-11
  • 2012-03-04
  • 1970-01-01
  • 1970-01-01
  • 2012-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多