0

I have problem with error LNK2001: unresolved external symbol.

I have a class CThread split to CThread.h and CThread.cpp

In CThread.h i have included boost/thread/tss.hpp, i have also 2 class:

CThreadLocalStorageSlot and CThread : public CThreadLocalStorageSlot (derived).

in class CThreadLocalStorageSlot i have:

static boost::thread_specific_ptr ThreadLocalStorage_;

but in linking time i have:

1>CThread.obj : error LNK2001: unresolved external symbol "public: static class boost::thread_specific_ptr CThreadLocalStorageSlot::ThreadLocalStorage_" (?ThreadLocalStorage_@CThreadLocalStorageSlot@threads@2V?$thread_specific_ptr@VCThread@threads@@boost@@A)

Why ? i have included boost file which is responsible for TLS so i have definition of thread_specific_pt.

Any sugestion ?

Best regards

user3626411
  • 188
  • 2
  • 3
  • 15
  • 1
    You are linking the with the correct boost_thread library I suppose? And you also have a definition for your static class member variable? – πάντα ῥεῖ Jan 14 '15 at 14:52
  • Yep, i have #include in my header. And CThread.h looks like: #include class __declspec(dllexport) CThreadLocalStorageSlot { public: static boost::thread_specific_ptr ThreadLocalStorage_; }; class __declspec(dllexport) CThread : public CThreadLocalStorageSlot { //class implementation } – user3626411 Jan 14 '15 at 14:56
  • 1
    That doesn't answer my question about you've been linking with the library. Anyway your fault is the missing definition for `CThreadLocalStorageSlot::ThreadLocalStorage_`. – πάντα ῥεῖ Jan 14 '15 at 14:58
  • Could you give me some example of definition which i have to write, because i have pointer to tls and i could use this ptr somewhere else in code, for example ThreadLocalStorage_.reset(new CThread). – user3626411 Jan 14 '15 at 15:03
  • The syntax is explained in the dupe. – πάντα ῥεῖ Jan 14 '15 at 15:04

0 Answers0