As said in the comments by Praetorian, std::call_once
need to call the system threading library. More specifically, it will call __gthread_once
. If the executable is not linked to pthread, that function will return -1
and will then cause the exception to be thrown.
To make a program pthread-enabled -pthread
option needs to be passed both to compiler and linker, as stated in gcc documentation. Just linking with -lpthread
sometimes is not enough and not just because of additional macros. For CMake users there is an out of the box module that can help adding support for pthread (or any system threading library) that can be used like that:
find_package(Threads REQUIRED)
target_link_libraries(myTarget PRIVATE Threads::Threads)
This will add any required compile and link flags if necessary.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…