c++ - ld 的奇怪警告

标签 c++ gcc warnings ld

我从 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/

相关文章:

c++ - 返回无法按值复制的对象

c++ - 编译琐事 : error ' ... ' does not name a type

c++ - 用于结构指针的 priority_queue 的自定义比较函数

c++ - 将 const 添加到 size_t 会导致编译失败是标准行为吗?

c++ - 无法识别 GMock 宏? YCM 给我错误,但 Bazel 构建良好

c++ - 在 if 语句中沉默 -Wunused-variable

.net - Visual Studio 2010 - 仅对事件文件显示警告

c++ - 重置 boost 累加器 C++

xcode - 如何删除OSX-GCC安装程序?

c++ - 背后的原因:尽管按名称返回,本地变量 'derived'仍将被复制