LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-23-2003, 01:24 PM   #1
c12ayon
LQ Newbie
 
Registered: Oct 2003
Posts: 28

Rep: Reputation: 15
about pthread


hi all.
i have a project related to pthread. and i don't know how to use it. anyone can tell me where i can get information about this?
and one other thing, where's the library of gcc? i can't find it.
thx before.
 
Old 10-23-2003, 01:56 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
The runtime library is usually installed in the /opt tree.
I've also seen it where it's in /usr/ccs

Try

> find /opt -name crt0.o
 
Old 10-23-2003, 02:44 PM   #3
dorian33
Member
 
Registered: Jan 2003
Location: Poland, Warsaw
Distribution: LFS, Gentoo
Posts: 591

Rep: Reputation: 32
you need use '-lpthread' switch with the gcc invocation; the library is named of course libpthread.so and is located usually in /usr/lib/
 
Old 10-24-2003, 03:49 AM   #4
c12ayon
LQ Newbie
 
Registered: Oct 2003
Posts: 28

Original Poster
Rep: Reputation: 15
#include <stdio.h>
#include <pthread.h>

void start(void);

int x = 0;

int main(void)
{
pthread_t threadID;

printf("%d\n", x);

pthread_create(&threadID, NULL, (void *)start, NULL);

sleep(3); /* sleep for eternity to allow for thread completion */

printf("%d\n", x);

return 0;
}

void start(void)
{
x = 10;
}

=========================
the output:
/tmp/ccQumZET.o(.text+0x44): In function `main':
: undefined reference to `pthread_create'
collect2: ld returned 1 exit status

what happen?
 
Old 10-24-2003, 05:53 AM   #5
dimm_coder
LQ Newbie
 
Registered: Oct 2003
Location: Minsk, Belarus
Distribution: Mandrake, FreeBSD
Posts: 28

Rep: Reputation: 15
Like it was mentioned above, U need to use -lpthread on the linking step.
Did U use it?
 
Old 10-24-2003, 12:45 PM   #6
c12ayon
LQ Newbie
 
Registered: Oct 2003
Posts: 28

Original Poster
Rep: Reputation: 15
i don't really get ur point, how to link it?
 
Old 10-25-2003, 04:37 AM   #7
c12ayon
LQ Newbie
 
Registered: Oct 2003
Posts: 28

Original Poster
Rep: Reputation: 15
gcc -o <filename> <filename>.c -lpthread

^^v
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pthread JanusPaul Programming 8 02-09-2005 05:46 PM
pthread zaman Programming 6 08-29-2004 04:04 PM
pthread and C++ gt73 Programming 17 11-04-2003 03:01 AM
need help about pthread c12ayon Programming 1 10-24-2003 07:47 AM
Pthread rch Programming 1 05-28-2003 02:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration