undefined引用`tan'但是包含了math.h

mah*_*ood 0 math gcc

我想从http://pages.cs.wisc.edu/~travitch/pthreads_primer.html(Mutex部分)编译示例pthread代码.当我运行此命令时:

 gcc -pedantic -Wall -o theaded_program pth.c -lpthread 
Run Code Online (Sandbox Code Playgroud)

在链接中说明,我收到此错误

pth.c:45:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
/tmp/ccajksBv.o: In function `opponent':
pth.c:(.text+0x4a): undefined reference to `tan'
/tmp/ccajksBv.o: In function `main':
pth.c:(.text+0x131): undefined reference to `tan'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

但是#include <math.h>代码中有!! gcc版本是4.6

rra*_*alf 7

您应该将-lm添加到编译器选项中.

除此之外,您还可以将-lpthread更改为-pthread.