How do I compile a C program with threads in gcc?

What parameter do I need to use with gcc to get rid of the errors?

-4


source to share


1 answer


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.

+11


source







All Articles