Undefined ref to 'function<void ()()>::operator()() const' when called from free function defined in cc file.

Chris Fairles chris.fairles@gmail.com
Sat Aug 30 05:22:00 GMT 2008


On Fri, Aug 29, 2008 at 9:03 AM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> Hi Chris,
>>
>> I was working on call_once and got this odd error:
>>
>> bin/ld: lib64/libstdc++.so: undefined reference to 'std::function<void
>> ()()>::operator()() const'
>> bin/ld: lib64/libstdc++.so: undefined reference to 'std::function<void
>> ()()>::function(std::function<void ()()> const&)'
>> collect2: ld returned 1 exit status
>>
>
> This is happening *inside* the library.
>>
>> Disregarding the actual run-time context here, semantically what could
>> be causing this? extern "C" has nothing to do with it it seems. After
>> commenting out the construction of __f and the call __f(), the errors
>> disappear. I've also added:
>>
>> _ZSt17__once_proxy_lock;
>> _ZSt18__once_proxy_mutex;
>> _ZSt19__once_proxy_object;
>> __once_proxy;
>>
>
> So, this is not really relevant, I think.
>>
>> to gnu.ver as per usual.
>>
>> "nm mutex.o" shows:
>> U _ZNKSt8functionIFvvEEclEv
>> U _ZNSt8functionIFvvEEC1ERKS1_
>> W _ZNSt8functionIFvvEED1Ev
>>
>
> I suspect this has to do with the fact that the *.cc files are built with
> -fno-implicit-templates. Try to make sure the required instantiation
> actually happens, be explicit?!?
>

Bingo. -fno-implicit-templates is indeed the issue. explicitly
instantiating "template class function<void()>" makes the linker
happy. Good to know.

Thanks for the help,

Chris

(PS. by tomorrow I should be ready to submit patches for at least
<mutex> and <condition_variable> w/ testacse, changlogs etc. I do have
a working <thread> too but w/o proper test cases so it will probably
be a separate submission after mutex and condition_variable).

> Paolo.
>



More information about the Libstdc++ mailing list