concurrencpp icon indicating copy to clipboard operation
concurrencpp copied to clipboard

Cannot link to shared builds of the library on Windows

Open chausner opened this issue 3 years ago • 0 comments

concurrencpp currently sets

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)

in order to work around the need on Windows to explicitly declare DLL exports. However, when trying to link to the library built as a shared target, I get the following linker errors:

coroutine_promise_tests.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: static struct conc
urrencpp::details::coroutine_per_thread_data concurrencpp::details::coroutine_per_thread_data::s_tl_per_thread_data" (?
s_tl_per_thread_data@coroutine_per_thread_data@details@concurrencpp@@2U123@A)" in Funktion ""private: static class conc
urrencpp::result<void> __cdecl concurrencpp::executor::submit_bridge$_InitCoro$2<void,class concurrencpp::worker_thread
_executor,class `struct concurrencpp::null_result __cdecl concurrencpp::tests::initialy_rescheduled_null_result_coro(st
ruct concurrencpp::executor_tag,class std::shared_ptr<class concurrencpp::worker_thread_executor>,class std::thread::id
,class std::shared_ptr<class concurrencpp::worker_thread_executor>,class std::shared_ptr<class concurrencpp::worker_thr
ead_executor>,class std::shared_ptr<class concurrencpp::worker_thread_executor>,class concurrencpp::tests::testing_stub
,bool)'::`2'::<lambda_1> >(struct concurrencpp::executor_tag,class concurrencpp::worker_thread_executor &,class `struct
 concurrencpp::null_result __cdecl concurrencpp::tests::initialy_rescheduled_null_result_coro(struct concurrencpp::exec
utor_tag,class std::shared_ptr<class concurrencpp::worker_thread_executor>,class std::thread::id,class std::shared_ptr<
class concurrencpp::worker_thread_executor>,class std::shared_ptr<class concurrencpp::worker_thread_executor>,class std
::shared_ptr<class concurrencpp::worker_thread_executor>,class concurrencpp::tests::testing_stub,bool)'::`2'::<lambda_1
>)" (??$submit_bridge$_InitCoro$2@XVworker_thread_executor@concurrencpp@@V<lambda_1>@?1??initialy_rescheduled_null_resu
lt_coro@tests@2@YA?AUnull_result@2@Uexecutor_tag@2@V?$shared_ptr@Vworker_thread_executor@concurrencpp@@@std@@Vid@thread
@9@111Vtesting_stub@52@_N@Z@$$V@executor@concurrencpp@@CA?AV?$result@X@1@Uexecutor_tag@1@AEAVworker_thread_executor@1@V
<lambda_1>@?1??initialy_rescheduled_null_result_coro@tests@1@YA?AUnull_result@1@0V?$shared_ptr@Vworker_thread_executor@
concurrencpp@@@std@@Vid@thread@std@@222Vtesting_stub@71@_N@Z@@Z)".

The error is about this variable in promises.h:

static thread_local coroutine_per_thread_data s_tl_per_thread_data;

Note the following hint on WINDOWS_EXPORT_ALL_SYMBOLS:

For global data symbols, __declspec(dllimport) must still be used when compiling against the code in the .dll.

I tried adding __declspec(dllimport) to s_tl_per_thread_data but got another error indicating that symbols with thread-local storage cannot be part of a DLL interface.

If shared builds cannot be supported on Windows, I suggest to remove CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS and put a note into the README or CMakeLists.txt.

chausner avatar May 07 '22 11:05 chausner