【问题标题】:undefined reference with std::atomic<const memberfunctionpointer*>::store() in g++ 4.4在 g++ 4.4 中使用 std::atomic<const memberfunctionpointer*>::store() 的未定义引用
【发布时间】:2012-06-25 11:13:38
【问题描述】:

我有一个std::atomic,它包含一个指向成员函数的指针。在 g++ 4.4.5 中一切都可以正常编译,但在链接过程中出现此错误:

./pool.o: In function `pool::worker::worker(pool&, int, int)':
pool.cpp:(.text._ZN4pool6workerC1ERS_ii[pool::worker::worker(pool&, int, int)]+0x95): undefined reference to `std::atomic<void (pool::* const*)(unsigned int, unsigned int, pool::worker*)>::store(void (pool::* const*)(unsigned int, unsigned int, pool::worker*), std::memory_order) volatile'
./pool.o: In function `pool::worker::give_job(void (pool::* const&)(unsigned int, unsigned int, pool::worker*), unsigned int, unsigned int)':
pool.cpp:(.text._ZN4pool6worker8give_jobERKMS_FvjjPS0_Ejj[pool::worker::give_job(void (pool::* const&)(unsigned int, unsigned int, pool::worker*), unsigned int, unsigned int)]+0x142): undefined reference to `std::atomic<void (pool::* const*)(unsigned int, unsigned int, pool::worker*)>::store(void (pool::* const*)(unsigned int, unsigned int, pool::worker*), std::memory_order) volatile'
./pool.o: In function `pool::worker::soul()':
pool.cpp:(.text._ZN4pool6worker4soulEv[pool::worker::soul()]+0xf1): undefined reference to `std::atomic<void (pool::* const*)(unsigned int, unsigned int, pool::worker*)>::store(void (pool::* const*)(unsigned int, unsigned int, pool::worker*), std::memory_order) volatile'

我真的不明白为什么它试图链接到 store() 的易失性重载,在源代码中,指向成员函数的指针是 const,而不是 volatile(它会编译)。

使用 g++ 4.6.3 编译相同的代码

【问题讨论】:

    标签: c++ linker c++11 g++


    【解决方案1】:

    简单:GCC 4.4 不支持此功能,或者您所体验的方式已损坏。较新的 GCC 具有更好的支持,并且可以正常工作。

    【讨论】:

    猜你喜欢
    • 2016-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多