Gcc demystification under lpthreads

These days I am playing with a thread library and trying to implement some functions. One lesson says that to run the program, use:

gcc -lpthread -lrt -lc -lm project1.c scheduler.c -o out

First of all, I need a deep understanding of what gcc does on each line,

  • lpthread is used for what? what are the contributions of lrt -lc -lm?

  • project1.c and scheduler.c compiled together, and what should I understand? I checked the code and any of them are not included in project1.c or scheduler.c.

  • as a result, clearly gives a "way out".

Secondly, the author claims that you must use

./out number filename (For example, ./out 2 sample.txt)

To understand this, as I understand it, the main function gets a number and sample.txt as input. (?)

Thanks for your answers and let me know.

+3
3

-l . . GCC

, -lpthread libpthread.so( pthread.a) -lm -lrt, -lc

[lib] pthread [.so] - POSIX

[lib] m [.so] - (sin, cos, e.t.c.)

[lib] rt [.so] - POSIX

[lib] c [.so] - libc ( C)

.c .o ( ) .

, .

+8

-lxxx libxxx, , libpthread, librt, libc libm.

, libc - . libm - , , , . libpthread pthreads (, pthread_create), , / pthreads, .

project1.c scheduler.c, , , , .

.

+4

""

, -o out


gcc not only compiles your files .cinto files .o, but also links the compiled files and libraries that you specified with -l, along with the binary.


./out number filename (For example, ./out 2 sample.txt)

The number and file name are two parameters for your program with a name.

+1
source

Source: https://habr.com/ru/post/1746080/


All Articles