Home » C programming

Error - undefined reference to 'pthread_create' with C program in GCC Linux

Fixing undefined reference to 'pthread_create' in Linux

This is a common error while compiling C program in GCC/G++ Linux. This error occurs when you are using pthread_create function to create threads in your programs.

To fix this problem ensure following points:

  • Include header file pthread.h in your program.
  • Add –lpthread linker flag with compilation command.

1- Include Header file

    #include <stdio.h>
    #include <pthread.h>
    ...
    ...

2- Compile command

    gcc  main.c -o main -lpthread

To more explanation : C program with pthread.h library in Linux.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.