I'm trying to complie and run my C program. The program uses threads. I'm running windows 10 using WSL with Ubuntu terminal. (Also trying it with Ubuntu virtual box) This is my "default" Makefile format im using for all my programs (changing name and flags for each)
CC=gcc
CFLAGS=-I. -w -pthread
DEPS = v1.h
version1: v1
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
v1: v1.o
$(CC) -o v1 v1.o
This is the first time im using threads in C which led me to discover -pthread. I found out you need to add it to the flags (which i did with CFLAGS). For some reason when i run this makefile above it got errors not finding pthread functions and i notice the way to fix it was by changing this line:
$(CC) -o v1 v1.o -pthread
adding pthread at the end. All this led me to make some research about flags in general and after searcing gcc's man page and google I found no simple answer for these questions:
- Why i needed to add -pthread to the .o task and .c task? Why it's not "enough" adding it to just one?
- What is -w flag? I know it stands for "Warnings" but what is the diffrent between -w and -Wall?
- What is -I. flag? Again, I found it stands for "include" but I'm not sure what its doing.. My makefile work with or without that flag.
Thank you.