Table of contents
Windows installation gcc, g++, pthread
When using the pthread function on Windows, an error is reported: the source file <pthread.h> cannot be opened, usually because the pthread library is missing. This article records the operation process of installing gcc, g++, pthread on windows .
Windows can install gcc, g++, and pthread in the form of mingw.
STEP 1: Download the mingw file
Open the webpage https://sourceforge.net/projects/mingw/files/ and download mingw-get-setup.exe
STEP 2: Install.exe
Run mingw-get-setup.exe to install mingw, you need to pay attention to the installation directory, remember the installation directory, you will need to set environment variables to use later.
STEP 3: Environment variable configuration
You need to modify the environment variable. Select Computer—Properties—Advanced System Settings—Environment Variables, find the Path variable in the system variables, and add the bin file directory under the min-gw installation directory, such as C:\MinGw\bin
STEP 4: Confirm that the installation of MinGw is successful
Win+r to open cmd, enter mingw-get, and the window of MinGw installation manager will pop up, which proves that the installation of MinGW is successful. At this time, the window of MinGW needs to be closed, otherwise an error will be reported.
STEP 5: Install gcc
Enter the command in the cmd window: mingw-get install gcc to install gcc
STEP 6: Install g++
Enter the commands mingw-get install g++ and mingw-get install gdb
STEP 7: View gcc
Enter gcc -v in cmd to check whether the gcc installation is successful
STEP 8: Install pthreads
Enter the command mingw-get install pthreads
Use windows with vscode
Terminal input gcc -v
Compile Linux multithreaded code
Enter gcc main.c thrd_pool.c -o main -lpthread