I want to compile the sample pthread code from http://pages.cs.wisc.edu/~travitch/pthreads_primer.html (Mutex section). As I run this command:
gcc -pedantic -Wall -o theaded_program pth.c -lpthread
which is stated in the link, I get this error
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
However #include <math.h>
is there in the code!! The gcc version is 4.6
You should add -lm to your compiler option.
Besides of that, you could also change -lpthread to -pthread.
In the end, it has to be like this: gcc -pedantic -Wall -o theaded_program pth.c -pthread -lm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With