I have a C program that I have been working on across multiple machines, and although it compiles correctly on my MacBook, I cannot get the program to compile on the Windows Subsystem for Linux, running Ubuntu 18.04 and using gcc.
The program spawns multiple threads, and when I try to compile it on the Windows Subsystem I get the error undefined reference to `pthread_create
.
Several other questions, such as this, this, and this, suggest using -lpthread
as a compiler flag to solve the issue, but I am already doing this and it compiles fine on OSX, so I suspect the issue might be related to my WSL configuration.
My Makefile is:
CC = gcc
CCOPTS = -Wall -c -g -ggdb
LINKOPTS = -Wall -g -ggdb -lpthread
all: calc
calc: calc.o smp3_tests.o testrunner.o
$(CC) $(LINKOPTS) -o $@ $^
calc.o: calc.c calc.h
$(CC) $(CCOPTS) -o $@ $<
I am including the pthread header with #include <pthread.h>
and calling the pthread_create
function with pthread_create(&multiplierThread, NULL, multiplier, arg)
.
Does anyone know what could be causing this compiler error?