How to compile the multithread code with gcc

后端 未结 4 1425
耶瑟儿~
耶瑟儿~ 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 07:13

    Almost:

    gcc -o thread1 -I/usr/include/nptl -D_REENTRANT -L/usr/lib/nptl thread1.c -lpthread
    

    The *FLAGS variables contain the arguments that are passed to the compiler and linker invocartion, respectively. (In your case you're compiling and linking in one go.) Make sure to add libraries after your own object files.

提交回复
热议问题