作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
此命令行在 ubuntu 上运行良好(使用 C++ 和线程):
g++ -std=c++11 prog.cpp -o prog.out -lpthread
我的 makefile 爆炸了:
all: main
main: prog.o
g++ -o prog prog.o
prog.o: prog.cpp
g++ -std=c++11 -c prog.cpp -lpthread
我不确定,但看起来 -lpthread
标志没有被选中。已经很晚了,我已经在 makefile 上工作了两个小时,如有任何帮助,我们将不胜感激。
make 返回一个错误:对'pthread_create' 的 undefined reference
最佳答案
你忘了解释“blows up”的意思。
但大概它的意思是“链接失败”,那是因为你把它放在了错误的命令上。
-l
是一个链接器 标志,但您在编译 命令中有它。
您需要将它移动到 main
目标。
你还记下了make rule #2 (来自 GNU make 维护者):
Every non-.PHONY rule must update a file with the exact name of its target.
Make sure every command script touches the file “$@“–not “../$@“, or “$(notdir $@)“, but exactly $@. That way you and GNU make always agree.
如果您想利用 built-in rules,您还可以大大简化您的 makefile(基本上什么都不做) .
CPPFLAGS := -std=c++11
LDLIBS := -lpthread
all: prog
就是这样。
关于c++ - G++ 命令行使用线程标记,linux makefile 不使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33817701/
我是一名优秀的程序员,十分优秀!