Results 1 to 3 of 3
Ok so I was messing around trying to learn about threads and how to use them and now I'm trying to compile but I get an error like this:
fatal ...
- 03-11-2011 #1Just Joined!
- Join Date
- Mar 2011
- Location
- pittsburgh
- Posts
- 44
[SOLVED] Problem with pthread.h, compiling with gcc
Ok so I was messing around trying to learn about threads and how to use them and now I'm trying to compile but I get an error like this:
fatal error: pthread: No such file or directory
however I have included the pthread.h header in my source file and the arguments I'm passing to gcc goes as follows:
and when I do aCode:gcc thread.c -o thread -lpthread
I get /usr/include/pthread.h so it seems to be here. I'm rather confused.Code:whereis pthread.h
- 03-11-2011 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Perhaps this sample will help:
producing:Code:#!/usr/bin/env bash # @(#) s1 Demonstrate compilation of pthreads code. # Utility functions: print-as-echo, print-line-with-visual-space. pe() { for i;do printf "%s" "$i";done; printf "\n"; } pl() { pe;pe "-----" ;pe "$*"; } FILE=${1-pt.c} pl " Sample of $FILE (local command specimen):" pe specimen $FILE pl " Results of compiling $( wc -l < $FILE ) lines of file $FILE:" gcc -lpthread $FILE ls -lgG a.out exit 0
Code from Linux Tutorial: POSIX Threads q.v.Code:% ./s1 ----- Sample of pt.c (local command specimen): Edges: 5:0:5 of 36 lines in file "pt.c" #include <stdio.h> #include <stdlib.h> #include <pthread.h> void *print_message_function( void *ptr ); --- { char *message; message = (char *) ptr; printf("%s \n", message); } ----- Results of compiling 36 lines of file pt.c: -rwxr-xr-x 1 9617 Mar 11 05:20 a.out
Best wishes ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 03-11-2011 #3



