gpt4 book ai didi

c - Makefile 更改 -lpthread 参数位置?

转载 作者:太空宇宙 更新时间:2023-11-04 02:26:50 27 4
gpt4 key购买 nike

我有一个服务器,它只在我执行 gcc server.c -o server -lpthread 时编译,但我的 makefile 是作为 gcc -lpthread server.c -o server 只是给我 undefined reference 错误。如何更改 -lpthread 位置?

这是文件:

CC=gcc
CFLAGS=-lpthread

all: server
server: server.c

clean:
rm -f server

run:
server
./server

最佳答案

库列表应该转到 LDLIBS,而不是 CFLAGS。来自manual :

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,参数应该在编译器调用中的正确位置,在输入文件之后。

关于c - Makefile 更改 -lpthread 参数位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49896101/

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