Location of -lpthread in C Makefile

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

I'm pretty new to Makefiles in C. I am trying to figure out where I would put -lpthread in my makefile so I can implement posix threads in my C program. Below is my Makefile, thanks in advance.

CFLAGS  = -g -Wall LDFLAGS = CC      = gcc LD      = gcc  TARG1   = calc OBJS1   = calc.o   $(TARG1): $(OBJS1)     $(LD) $(LDFLAGS) $(OBJS1) -o $(TARG1) clean:     rm -rf $(TARG1) $(OBJS1)

回答1:

I would recommend not using -l. Instead give GCC -pthread on both the CFLAGS and LDFLAGS variables. This will make sure that preprocessor defines are properly set during the compile and it will link the correct libraries.

This assumes GCC of course. If using Intel icc or LLVM check for the right parameters.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!