bshoshany / thread-pool

BS::thread_pool: a fast, lightweight, and easy-to-use C++17 thread pool library
MIT License
2.21k stars 253 forks source link

[BUG ?] multiple definitions get_index, get_pool link fails with VS 2022 #134

Closed Nelson-numerical-software closed 10 months ago

Nelson-numerical-software commented 10 months ago

Describe the bug

in my specific environment on Windows, maybe not reproductible in others cases: get_index, get_pool seems to be redefined each time that we include "#include "

4>LINK : D:\Developpements\Github\nelson-lang\nelson\bin\x64\libnlsParallel_builtin.dll introuvable ou non généré par la dernière édition de liens incrémentielle ; édition de liens complète en cours
4>backgroundPool_deleteBuiltin.obj : error LNK2005: "class BS::this_thread::thread_info_index BS::this_thread::get_index" (?get_index@this_thread@BS@@3Vthread_info_index@12@A) déjà défini(e) dans backgroundPoolBuiltin.obj
4>backgroundPool_deleteBuiltin.obj : error LNK2005: "class BS::this_thread::thread_info_pool BS::this_thread::get_pool" (?get_pool@this_thread@BS@@3Vthread_info_pool@12@A) déjà défini(e) dans backgroundPoolBuiltin.obj
4>backgroundPool_displayBuiltin.obj : error LNK2005: "class BS::this_thread::thread_info_index BS::this_thread::get_index" (?get_index@this_thread@BS@@3Vthread_info_index@12@A) déjà défini(e) dans backgroundPoolBuiltin.obj
4>backgroundPool_displayBuiltin.obj : error LNK2005: "class BS::this_thread::thread_info_pool BS::this_thread::get_pool" (?get_pool@this_thread@BS@@3Vthread_info_pool@12@A) déjà défini(e) dans backgroundPoolBuiltin.obj
4>backgroundPool_fieldnamesBuiltin.obj : error LNK2005: "class BS::this_thread::thread_info_index BS::this_thread::get_index" (?get_index@this_thread@BS@@3Vthread_info_index@12@A) déjà défini(e) dans backgroundPoolBuiltin.obj
4>backgroundPool_fieldnamesBuiltin.obj : error LNK2005: "class BS::this_thread::thread_info_pool BS::this_thread::get_pool" (?get_pool@this_thread@BS@@3Vthread_info_pool@12@A) déjà défini(e) dans backgroundPoolBuiltin.obj
4>backgroundPool_getBuiltin.obj : error LNK2005: "class BS::this_thread::thread_info_index BS::this_thread::get_index" (?get_index@this_thread@BS@@3Vthread_info_index@12@A) déjà défini(e) dans backgroundPoolBuiltin.obj
4>backgroundPool_getBuiltin.obj : error LNK2005: "class BS::this_thread::thread_info_pool BS::this_thread::get_pool" (?get_pool@this_thread@BS@@3Vthread_info_pool@12@A) déjà défini(e) dans backgroundPoolBuiltin.obj
4>backgroundPool_structBuiltin.obj : error LNK2005: "class BS::this_thread::thread_info_index BS::this_thread::get_index" (?get_index@this_thread@BS@@3Vthread_info_index@12@A) déjà défini(e) dans backgroundPoolBuiltin.obj
4>backgroundPool_structBuiltin.obj : error LNK2005: "class BS::this_thread::thread_info_pool BS::this_thread::get_pool" (?get_pool@this_thread@BS@@3Vthread_info_pool@12@A) déjà défini(e) dans backgroundPoolBuiltin.obj
4>backgroundPool_usedBuiltin.obj : error LNK2005: "class BS::this_thread::thread_info_index BS::this_thread::get_index" (?get_index@this_thread@BS@@3Vthread_info_index@12@A) déjà défini(e) dans backgroundPoolBuiltin.obj

workaround used (ugly ?)

add inline:

    inline thread_local thread_info_index get_index;
    inline thread_local thread_info_pool get_pool;

System information

JanCaha commented 10 months ago

+1

I am getting the same error on Linux with g++-12 compiler.

lucadesogus commented 10 months ago

+1 Same issue on Debian 12 with g++12.2.0

bshoshany commented 10 months ago

Hi everyone, thanks for opening this issue! It does appear that changing these variables to inline resolves this issue. I will post a patch in a bit.

bshoshany commented 10 months ago

Update: This should now be resolved in v4.0.1. Please let me know if it is not resolved.