Makefile改变-lpthread参数位置?

时间:2018-04-18 09:30:21

标签: c makefile

我有一台服务器只在我执行gcc server.c -o server -lpthread时编译,但我的makefile以gcc -lpthread server.c -o server的形式编写,只是提交了未定义的引用错误。如何更改-lpthread位置?

这是文件:

CC=gcc
CFLAGS=-lpthread

all: server
server: server.c

clean:
    rm -f server

run:
    server
    ./server

2 个答案:

答案 0 :(得分:2)

图书馆列表应该转到LDLIBS,而不是CFLAGS。来自manual

  

LDLIBS

     

当应该调用链接器时,为编译器提供的库标志或名称,'ld'。 LOADLIBES是LDLIBS的弃用(但仍受支持)替代方案。非库链接器标志(如-L)应包含在LDFLAGS变量中。

通过使用LDLIBS,在输入文件之后,参数应该在编译器调用中的正确位置。

答案 1 :(得分:0)

You need to use -pthread command line option for both compiling and linking-lpthread既不充分又不必要:

CFLAGS := -pthread
LDFLAGS := -pthread