🐛 BUG — static linking thread
Date: 2023-03-28Last modified: 2023-12-22
Table of contents
Introduction
Program that uses thread can crashes if statically linked.
Minimal program to test the faillure
#include <condition_variable>
int main() {
std::condition_variable a;
return 0;
}
Makefile
bin/static_link_failure: static_link_failure.cpp
g++ --std=c++11 -static -pthread $^ -lpthread -o $@.g++.static
clang++ --std=c++11 -static -pthread $^ -lpthread -o $@.clang++.static
g++ --std=c++11 -pthread $^ -lpthread -o $@.g++.non_static
clang++ --std=c++11 -pthread $^ -lpthread -o $@.clang++.non_static
clang++ --std=c++20 -pthread $^ -lpthread -o $@
output/static_link_failure.txt: bin/static_link_failure
echo "bin/static_link_failure.g++.static" > $@
bin/static_link_failure.g++.static || echo "FAIL" >> $@
echo "bin/static_link_failure.clang++.static" >> $@
bin/static_link_failure.clang++.static || echo "FAIL" >> $@
echo "bin/static_link_failure.g++.non_static" >> $@
bin/static_link_failure.g++.non_static || echo "FAIL" >> $@
echo "bin/static_link_failure.clang++.non_static" >> $@
bin/static_link_failure.clang++.non_static || echo "FAIL" >> $@
Possible output
bin/static_link_failure.g++.static
bin/static_link_failure.clang++.static
bin/static_link_failure.g++.non_static
bin/static_link_failure.clang++.non_static