gpt4 book ai didi

c - pthreads 编译的问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:54:41 25 4
gpt4 key购买 nike

当我尝试使用 Makefile 进行编译时,似乎我遇到了 pthread 问题:

/csapp.c:462: undefined reference to `pthread_create'

我认为这可能与 -lpthread 有关?这是我的 Makefile(是的,它们被标记了一次):

CC = gcc
CFLAGS = -Wall -g
LDFLAGS = -lpthread

OBJS = proxy.o csapp.o

all: proxy

proxy: $(OBJS)

csapp.o: csapp.c
$(CC) $(CFLAGS) -c csapp.c

proxy.o: proxy.c
$(CC) $(CFLAGS) -c proxy.c
clean:
rm -f *~ *.o proxy

最佳答案

我认为您的问题出在 LDFLAGS 上。

来自 10.3 Variables Used by Implicit Rules :

LDFLAGS Extra flags to give to compilers when they are supposed to invoke the linker, ld, such as -L. Libraries (-lfoo) should be added to the LDLIBS variable instead.

LDLIBS Library flags or names given to compilers when they are supposed to invoke the linker, ld. LOADLIBES is a deprecated (but still supported) alternative to LDLIBS. Non-library linker flags, such as -L, should go in the LDFLAGS variable.

所以尝试:

LDLIBS = -lpthread

关于c - pthreads 编译的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22061072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com