C++ thread dynamic link issue

Posted by Jingbiao on February 28, 2022, Reading time: Less than 1 minute.

For multithreading concurrent program in C++, for example:

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <thread>
void thread_init() {
std::cout<<"This statement is executed in the new thread\n";
}
int main() {
std::thread t(thread_init);
std::cout<<"This statement is executed in the main thread\n";
t.join();
}

This error might occur due to dynamic library error img

Solution:

Compile with argument:

1
-static-libgcc -static-libstdc++

Reference

  1. https://stackoverflow.com/questions/48505719/c-procedure-entry-point-not-found-with-mingw