How do I compile a C program with threads in gcc?
On Linux, you must first compile
gcc -g -Wall -pthread yourcode.c -lpthread -o yourprogram
-g
asks for debug information, -Wall
asks for all warnings, -pthread
asks for POSIX thread support.
when it compiles without warnings and you debug it with gdb
, you might want to optimize the compiler by replacing (or adding after) -g
to-O2
Very soon you will want to make your program out of several compilation units (linked together). Then you need to learn how to use a builder like GNU make and you will have Makefile
(don't forget the tabs are significant inside them).
You should of course use a source control system (I suggest using git , perhaps via gitorious or github ) in your source code.
source to share