Link with -pthread instead of -lpthread The canonical way to link with the thread library is to use -pthread, which brings in additional libraries like libatomic.so on riscv64. However cmake defaults to link with -lpthread which only bring the libpthread.so library. Fortunately it has the option THREADS_PREFER_PTHREAD_FLAG for that, which is "highly recommended" but not the default.