How to compile the multithread code with gcc

后端 未结 4 1424
耶瑟儿~
耶瑟儿~ 2021-01-16 06:43

I have seen the given two makefiles as follows:

all: thread1 thread2 thread3

CFLAGS=-I/usr/include/nptl -D_REENTRANT
LDFLAGS=-L/usr/lib/nptl -lpthread

clea         


        
4条回答
  •  生来不讨喜
    2021-01-16 06:59

    If your code don't have external dependencies beyond pthread:

    gcc thread1.c -o thread1 -D_REENTRANT -lpthread
    

    Quote:

    Defining _REENTRANT causes the compiler to use thread safe (i.e. re-entrant) versions of several functions in the C library.

提交回复
热议问题