|
Boost : |
Subject: Re: [boost] [threads] Unexpected behaviour of Thread loal storage
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2015-04-29 09:55:29
On Wed, Apr 29, 2015 at 4:40 PM, Fu ji <fujimailing_at_[hidden]> wrote:
> Maybe it's because in solutionB I have delaration of tls (in other way I
> have problem with building solution:
>
> file.obj : error LNK2001: unresolved external symbol "public: static class
> boost::thread_specific_ptr<classnamespace::CClass>
> namespace::CThreadLocalStorageSlot::ThreadLocalStorage_"
> (?ThreadLocalStorage__at_CThreadLocalStorageSlot@tnamespace@
> @2V?$thread_specific_ptr_at_VCThread@namespace@@@boost@@A)
>
> )
You have to declare the TLS variable in the header, it has to have
external linkage. Given that you have two dlls, it must also be
exported. For example:
// tls.h
extern API boost::thread_specific_ptr<int> TLS;
Then you have to define this object in one cpp file of SolutionC, like this:
// tls.cpp
#include "tls.h"
API boost::thread_specific_ptr<int> TLS;
Here API is a macro which is defined to __declspec(dllexport) when you
build SolutionC and __declspec(dllimport) otherwise.
PS: This is really not a Boost-related question. You need to
understand how linking works on Windows in general.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk