What about the compilation error when using the thread class in C++
This article mainly shows you the "C++ using thread classes when compiling errors how to do", the content is easy to understand, well-organized, I hope it can help you solve their doubts, the following let the editor lead you to study and learn about "C++ thread classes when compiling errors when how to do" this article.
/ tmp/ccM2tvqF.o: In function `main':
Thread_c.c: (.text + 0x1f): undefined reference to `pthread_create'
Thread_c.c: (.text + 0x52): undefined reference to `pthread_create'
Thread_c.c: (.text + 0x7d): undefined reference to `pthread_join'
Thread_c.c: (.text + 0xa9): undefined reference to `pthread_join'
Collect2: ld returned 1 exit status
After checking for a long time, I thought there was a problem with the code, and finally I found out that because the pthread library is not the default library of the Linux system, we need to use the library libpthread.a when connecting, so when we use pthread_create to create a thread, we should add the-lpthread parameter: gcc test_thread.c-lpthread-o test_thread. After adding this, the compilation is successful!
These are all the contents of this article entitled "what to do when compiling errors when using thread classes in C++". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!