user426807
user426807

Reputation: 9

Compiling errors in a program using threads

On compiling I am getting an error "undefined reference to pthread_create()" and similarly for "undefined reference to pthread_join()". What are the possible reasons? I am unable to identify them.

Upvotes: 0

Views: 135

Answers (2)

Tronic
Tronic

Reputation: 10430

You should add -pthread, which adds the required flags for the preprocessor as well as the linker. The flag suggested by others, -lpthread, only links the library, which may lead to the system libraries not having proper threading support.

Upvotes: 0

spencer nelson
spencer nelson

Reputation: 4525

Are you sure you remembered the -lpthread flag in compilation? Usually that's the source of this error.

Upvotes: 6

Related Questions