in these days i'm playing with thread library and trying to implement some functions. One of the tutorial says that to run the program use :
gcc -lpthread -lrt -lc -lm project1.c scheduler.c -o out
first of all i need deep understanding of what is gcc doing in each line,
lpthread is used for what? what are the contributions of lrt -lc -lm ?
project1.c and scheduler.c is compiled together so what should i understand? i checked
the code and any of them not included in project1.c or scheduler.c.
secondly the author states that to run the program you have to use
./out number filename (For example, ./out 2 sample.txt)
To make these clear as far as i understand the main function gets number and sample.txt as an input.(?)
thanks for your answers and making me clear.
-l parameter means - link to a specific library. See GCC manual for more information
Thus -lpthread means link to libpthread.so (or pthread.a)
Likewise for -lm -lrt, -lc
[lib]pthread[.so] - POSIX threads
[lib]m[.so] - math standard library (sin, cos, e.t.c.)
[lib]rt[.so] - POSIX realtime extensions
[lib]c[.so] - libc (standard C library)
Each of your .c files are compiled to .o object file (these are called compilation units) and are linked together with the above mentioned libraries.
You are right about how command line parameters should be passed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With